Python Leaning Notes #2
General functions
- len(), will calculate the length of string, array, …
String Methods
- upper(), to all capitalized string
- lower(), to all lower case character string
- title(), to first character will be capitalized
- find(), return the first index of the search character or string
- replace(), replace the search string with the provided new string
in operatoer
- ‘abcde’ in ‘zabcdef’ will return True
- ‘abcde’ in ‘def’ will return False
Math operators
- addition: +, or you can use +=
- subtraction: -, or you can use -=
- multiplication: *, or you can use *=
- double ** means power, or you can use /=
- division: /
- double // mean to get the integer after division, like 10 // 3 = 3
- % means after division and get the remainder, like 10 % 3 = 1
math module
- import math module: import math
- math.ceil()
- math.abs()
Condition statement
- if condtion #1:
- elif condition #2:
- else:
Logic operators
- AND: and, all conditions have to be True
- OR: or, any of conditions is True, then return True
- NOT: not, reverse a boolean
Comparison operators
- after using comparison operators, it will return a boolean value
- >, >=, <, <=, ==, !=
while loop
- syntax: while condition: … else: …
- in while, you can use break to jump out from loop immediately