New Page
Python Command Index
| print string ("") or variable value (). | |
| variable = value | Set a variable. space and comma seperated. |
| input | prompt user input |
data types and conversion
integer (int)- whole number
floating point (float) - decimal
boolean (bool) - true or false
string (str) - string
Python notes
name = input ("What is your name? ")
age = input ("How old are you? ")
new_patient = input ("Are you a new patient? ")
print(name, age, new_patient)
Type Conversion
birth_year = input ("Enter your birth year ")
age = 2024 - int(birth_year)
print (age)
datatype(variable_to_convert)+
Basic number + number
first_number = float(input("First: ")) ##variable is set as type float, and takes input from user
second_number = float(input("Second: ")) ##variable is set as type float, and takes input from user
total = (first_number) + (second_number) ##variable is set as the sum of first + second variables
print ("Sum " + str(total)) ##String Sum is printed, as well as the variable total. Python cannot concatenate different variable types.
variable options/methods
| (variable.find('string') | Search for a string. Prints index of finding |
| .upper/.lower |
upper and lower case |
| .replace('oldstring', 'newstring') |
Operators
+
/ - division floating point.
// - division integer
% - Modulus operator
Example
If you have 7 % 3, the operation would be:
- 7 divided by 3 equals 2 with a remainder of 1.
- So,
7 % 3equals 1.
** - exponent operator
to the power of
10 ** 2 = 10²