$ brew install python
What is REPL? REPL is the language shell. Its short for Read, Eval, Print and Loop. The process is:
$ python3 sample.py
input("How old are you?")
Reserved memory locations to store values.
identifier = expression
legal_age = 21
user_age = input('How old are you? ')
(Note the snake_case)
print('Hello World')
age = 21
print(f'I am {age}')
Tells the compiler or interpreter how the programmer intends to use the data
'String'
'Haikus are easy.\nBut sometimes they don\'t make sense.\n Refrigerator.'
name = "Josh Medeski"
'hello' + 'world'
Any whole number
number_of_employees = 53
bottles_of_beer_on_the_wall = 99
Any number with a decimal point.
pi = 3.141592
tax = 8.25
tax_percentage = 0.0825
year_born = int(input('What year were you born? '));
print(f'You were born in {year_born}')
Symbol | Operation |
---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
year_born = int(input('What year were you born? '));
years_ago = 2019 - year_born
print(f'You were born {years_ago} years ago')
5 + 30 * 20 / 10
((5 + 30) * 20) / 10
Symbol | Meaning |
---|---|
> | greater than |
< | less than |
>= | greater than or equal to |
<= | less than or equal to |
== | equal to |
!= | not equal to |
A binary value, either True
or False
is_nice = True
is_allowed_to_drive = False
Note: False, 0, None, “”, and empty collections like [] and {} are falsey otherwise it’s true
if condition:
# execute statement block
age = 30
if age >= 21:
print('Allowed to drink')
age = 18
if age >= 21:
print('Allowed to drink')
else:
print('This person is underage!')
age = 15
if age >= 16:
print('Allowed to drive')
elif age == 15:
print('Allowed to get a permit')
else:
print('Not allowed to drive')
iteration = 0
while iteration > 10:
print(f'This is iteration number {iteration}')
iteration += 1
print("Finished")
answer = ''
while answer != 'when':
answer = input('Say when: ')
answer = answer.lower()
print("Cheese")
while True:
answer = input('Say when: ')
if answer.lower() == 'when':
break
print("Cheese")