Data Types and Variables Flashcards
(text) string
“double quotes” and ‘single quotes’
implicit type casting
instead of string f= “fff”
you can do f = “fff” amd the result is the same
Comments
like this
Addition operator + for
a= “lol”
b=”no”
a + b
string concatonation of strings “andy” and “rom”
(combine)
print(“andy” + “rom”)
\n newline for “hello world” (print 3 lines)
print(“Hello World\nHello World\nHello World”)
Can operators have different variable types?
(Ex: a=5 , b=”lol” -> print(a + b)
No, the variable types must match
Alternating string quotes
Ex:String concatonation is done with the “+” sign.
How is this written?
(‘String Concatenation is done with the “+” sign.’)
input() function
input(“What is your name”)
Lets the user enter in a string
comments
single line
multiline
hey whats up
len function
Ex:
len(“fax”)
- string bn = “jams”
len(bn)
- # prints (the length of the string)
3
-#prints(length of the string)
4
Variable
labels for storing information(values)
Operator precedence
PEMDAS
Declaring a variable
Ex: Named result with a value of 3
result = 3
Expression
-Are these expressions?
3 * 3 , result + 4
anything that Python can evaluate to a value
-Yes!
Data type
-Is string and bool a data type?
classes and variables that are usually predefined
-Yes!
What does type() function do?
-Ex:
lmao = 5
type(lmao)
Output: ?
Shows the class or variable type of the variable
-
Variable/data type rules
- What can they include?
- What MUST they start with?
- Lowercase and uppercase letters,numbers and underscores: _
- letter or the underscore character and be case-sensitive