1 Python Object and Data Structure Basics Flashcards
What are the major python data types?
- integers int whole numbers Ex. 3 400 4
- floating point float numbers with a decimal point Ex. 3.0 4.5 7.887
- strings strordered sequwnced charaters Ex. “hello” “bye” “milk”
- lists list ordered sequwnce of objects Ex. [400,”bob”, 4.00]
- dictionaries dict unordered key:Value pairs Ex. {“name1”:”Bob”,”color”:”red”}
- tuples tup ordered sequwnce of immutable objects v objects Ex. (300,”Bob”,3.0)
- sets set unoreded collection of unique objects Ex. {“a”,”b”}
- booleans bool logical values Ex.
symbol for addtion
+
symbol for subtraction
-
symbol for mult
*
symbol for division
/
1.) symbol for modulo
2.) explain what it does
- %
- Gives you the remainder after division.
Example 7%4 will give you 3
Example 8%2 will give you 0
What is the symbol for exponents?
**
Example 2**3 will give you 8
what is a variable?
variables stores data types
what are some of the rules for naming variables?
- cannot start with a number
- cannot be spaces in the names(use _ intead of spaces)
- cannot use any of these symbols :’’’,<>?|()!@$%^&*^-+
- best practice to keep names lowercase
- avoid speacial names like “list” , “str” , “int” etc
what is dynamtic typing?
you can reassigned variables to different data types
Example:
dog = 5
dog = “Jolly”
print(dog)
the code should output “Jolly”
- what is and symbol of the type function
- what does it do?
- type()
- it tells the type of data type of something
Example: type(5) #it should output int
type(“Bob”) #it should output str
- Define what a string is
- how do you write strings
- Strings are sequence of charaters using the syntax to either signle quotes or double quotes
- Example:“Bob”, ‘pizza’, “ I don’t do that “
what is indexing in terms of strings?
indexing is the term you use when you want to grab a single chararter of a string. we us [] to get there character we want.
Example:
quote = “hello world”
quote[0] #output should be ‘h’
quote[8] #output should be ‘r’
quote[9] #output should be ‘l’
quote[-2] #output should be ‘l’

what is slicing in terms of strings?
slicing allows you to grab a subsection of muluple strings. It uses the following syntax:
[start:stop:step]
start = is the numerical index you want to for the slice start
stop = the index you want to end(but not include)
step = is the size of the “jump” you wish to take or skip by
example:
word = “abcdefghijk”
word[2:] #it should output ‘cdefghijk’
word[2:12] #it should output ‘cdefghijk’
word[:3] #it should output ‘abc’
word[0:3] #it should output ‘abc’
word[3:6] #it should output ‘def’
word[1:3] #it should output ‘bc’
word[::2] #it should output ‘adgj’
word[0:13:2] #it should output ‘adgj’
word[2:7:2] #it should output ‘ceg’
word[0:13:-1] #it should output ‘kjihgfedcba’
word[::-1] #it should output ‘kjihgfedcba’
what is the lenth fucntion in terms of strings?
len()
it tells you the length of a string
Example: len(“bob”) #It should output 3
len(“I am”) #it should output 4
How do you create comments in python?
By using hashtags
Example: #this is a comment
how do you make a string capitalize?
upper method
variable.upper()
Example: name = jason
cap_name = name.upper()
print(name) #should print jason
print(cap_name) #should print JASON
how do you make a string all lower case?
lower method
variable.lower()
what is the split method and what does it do in terms of strings?
split method
variable.split()
it turns a string into a list.the objects in the list are split by the spaces in the strinf
Example:
word = “hello world”
x = word.split()
print(x) #it should print [“hello”,”world”]
word2 = “hi this is a string”
y = word2.split(“i”)
print(i) #it should print [“h” ,”th” , “s a str” ,”ng”]
What does the format method does?

What are the 3 ways to perform string formatting?
- The oldest method involves placeholders using the modulo % character.
- An improved technique uses the .format() string method.
- The newest method, introduced with Python 3.6, uses formatted string literals, called f-strings.
How does the f-string format looks

How to format floats(decimals) in the f-string formatting?

How do you create a list

How to index and slice list?

- Which method add an element into list?
- Which method deletes an item in list?

- Which method reverse the order of a list?
- Which method puts a list in alphabetical order?

How can we nest list?

How do we create dictionary

How to create keys from an empty dictionary

How to nest dictionary

- Which dictionary method return a list of all keys
- Which dictionary method return a list of all values
- Which dictionary method return tuples of all items

How do we create a tuple

Which two methods are mostly use in tuples?

Why is main reason list differs from tuples?
Tuples are immutable, meaning once they are made, we cant add items in themYou may be wondering, “Why bother using tuples when they have fewer available methods?” To be honest, tuples are not used as often as lists in programming, but are used when immutability is necessary. If in your program you are passing around an object and need to make sure it does not get changed, then a tuple becomes your solution. It provides a convenient source of data integrity.
How do we make a set in python

What is the popular method use in sets?

How do we make things Booleans ?

How to write a text file

How to open a text file

How to read and close a text file

Alternate way to open text file

Alternate way to read text file

What are the different modes in the text files

Alternate way to append text file

Alternate way to write file
