0%
if-else
1 2 3 4
| if condition: do this else: do this
|
Operator and Meaning
1 2 3 4 5 6
| > : greater than < : less than >= : greater than ro equal to <= : less than or equal to == : equal to != : not equal to
|
Get remainder
1 2 3 4 5 6 7 8 9
| 7%2
number = int(input("Which number do you want to check?"))
if number % 2 == 0 : print('This is an even number.') else: print('Thisi is an odd number.')
|
Nested if statements and elif statements
1 2 3 4 5 6 7 8 9 10
| if condition: if another conditino: do this else: do shit elif condition2: do B else: do this
|
Logical Operators
補充
- The
lower()
function changes all the letters in a string to lower case.
- The
count()
function will give you the number of times a letter occurs in a string.