Python Basics Flashcards
what are some of the data types in Python?
int
str
float
set
list
tuple
dict
bool
what does “ * “ represent in python?
It is a symbol for multiplication
What does the “ / “ symbol represent in Python?
It is a symbol of division
What does the “ ** “ symbol represent in Python?
It is a symbol that means “ Raised to the power of”
What does this “ // “ symbol mean in Python?
It means divide and round it to the nearest integer.
What does the “ % “ symbol mean in Python?
The symbol is called a Modulo. The symbol returns a remainder value.
What are built-in functions?
Functions are “Actions” we (the user) can perform based on our preference.
What are some examples of Math functions?
“round” & “abs”
print(round(2.9))
Answer: 3
print(round(99.5)
Answer: 100
print(round(99.4))
Answer: 99
abs, returns the absolute value. Used for solving complex math.
What is operator precedence?
Precedence in general means “take priority over”..
In Python “operator precedence” means the rule of “PEMDAS”.
Variables
Store information that can be used in our programs.
It is like a container of information.
example of good and bad variables.
good variables: lower case, no numeric value in the beginning, not using all caps, not using names of built in functions.
bad variables: the opposite of good variables.
what are expressions and statements?
expressions are on the right side of the variables.
statements are the entire LINE of code. Just the line not the whole code with multiple lines.
Expression:
- Represents something
- python evaluates it
- results in a value
- Example: 5.6
- (5/3) +2.9
Statements:
- Does something
- python executes it
- results in an action
Example:
print(“hello user”)
import
return
Augmented Assignment Operator
it is a shorthand way to do math.use the math variable to add, sub, M, D, …
Example:
x = 5
x += 2
print(x) [Answer: 7]
x = x +2
print(x [Answer: 7]
the rule of PEMDAS can be used in AAO if needed.
String/str
It is a piece of text. It is written in double quotation marks
String Concatenation
Adding strings together. For example: (“hello”) + (“world”)
Type conversion
It is a process of converting a data type to another data type.
Example:
x = 100
x = str(100)
print(type(x))
Answer: str
We can do this conversion with int, float, str, etc.
Escape sequence
It is a way to add quotation marks in a string.
Example: “It’s always sunny”
Example: \n (#new line)
\t (#tab)
What are formatted strings?
its a function, invoked by (f {})
What is string indexes?
String index is 0 based, the next index is 1, and so on…
name = “Shehbaaz”
#comment: “01234567” is the string index for the variable (name)
What are some of the rules for using string index?
working string index requires the help of [] brackets.
[startpoint : endpoint]
[0:what ever the end is]
what is an example of string index?
“01234567”
Example1:
name = “Shehbaaz”
“01234567”
print(name[0:2])
#start on 0/S and at 2/e
answer: Sh
Example2:
print(name[0:7])
answer: Shehbaa
Example3: Stepover 1 time
print(name[0:8:1])
Answer: Shehbaaz
Example: 4 (0:8:2) means step over 2 times)
print(name[0:8:2])
answer: Seba
Example5: (negative sign and number will start counting from backward)
print(name[-1])
Answer: z
Example 6:
# [start:stop:stepover]
print(name[: :-1])
Answer: zaabhehS
What is Slicing?
It is used in string or list index, uses the rule of [start:stop] OR [start:stop:stepover]
What is immutability
Immutability means ‘Cannot Be Changed’
In python immutability means something that cannot be changed. string and tuple are unchangeable, once created, it exists in that form. It cannot be changed.
What are built in functions?
functions are actions we can perform.
so far we learned built in functions like abs() and round() for int.
There is len() for strings (len is short for length). #length starts count from 1. count from 0 is only in index.