Data Types and Variables Flashcards
(47 cards)
(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
Camel Case
- What is it for real cool person?
- Python naming convention for real cool person ?
Common variable naming convention
- realCoolperson
- Underscore real_cool_person
Escaping(for strings)
-Give an example in this(single quote):
It’s an escaped quote
-Give an example in this(double quotes):
I’m a so-called “scipt kiddie”
-Add a \ BEFORE the ‘ or “ to prevent confusion
‘It's an escaped quote!’
-“I’m a so-called "script kiddie"”
Multiline strings
-Ex:
This is line 1,
… this is line 2,
… this is line 3.
- Triple quotes
”"”This is line 1,
… this is line 2,
… this is line 3.”””
Multiline strings with quotes inside
-Ex: He said: “Hello, I’ve got a question” from the audience
-He said: “Hello, I’ve got a question” from the audience
‘a’ + ‘b’ OUTPUT?
‘a’ - ‘b’ OUTPUT?
- a+b
- Minus with string doesn’t work
mystring = “Hello World”
mystring.lower()
OUTPUT?
hello world