Python Course

The website is under construction.

Python Basics

Output with Python

print("Hello World!")
OUTPUT: Hello World

print is not the same as PRINT

print is a function where it outputs strings, integers, decimals, and mathematical calculations.



You can use the (+) operator to "add" or contacatenate two or more string together. It also allows you to place strings and variables together.

print("Hello" + "World!")

OUTPUT: HelloWorld!


displaying variables and numbers in your output:

Example:
name = "Ms. Friedman"
print ("Hello" + name)

OUTPUT: Hello Ms. Friedman


Calculations:

print (6 * 7 + 3)
OUTPUT: 45


print(10+5*7-2)
OUTPUT: 43


Escape Characters

Special characters are marked with the \
  • \n -new line
  • \t -tab
  • \" -prints a quote
  • \\ - prints a slash

Comments

Comments are text that are ignored by the programmer.
Developers use comments to describe the program and the functionality of certain blocks of code.
It is also used to aid new developers who are newly hired into the team.

In Python there are two different ways of adding comments.

For single line comments the # is used
Example:
#This is a comment

To add comments with multiple lines, use three quotes at the beginning and at the end of the comments.
Example:
""""
This is an example of
comments on multiple lines
""""


Assigning values to variables

num1 = 12
LastName = "Friedman"

Input

String Input
word = input()
or
word = input("Enter a word: ")
Example Run:
Enter a word: Computer

Integer Input
num = int(input("Enter a number: "))

Decimal Input
num = float(input("Enter a number: "))