1 Python Object and Data Structure Basics Flashcards

1
Q

What are the major python data types?

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

symbol for addtion

A

+

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

symbol for subtraction

A

-

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

symbol for mult

A

*

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

symbol for division

A

/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

1.) symbol for modulo

2.) explain what it does

A
  1. %
  2. Gives you the remainder after division.

Example 7%4 will give you 3

Example 8%2 will give you 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the symbol for exponents?

A

**

Example 2**3 will give you 8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what is a variable?

A

variables stores data types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what are some of the rules for naming variables?

A
  1. cannot start with a number
  2. cannot be spaces in the names(use _ intead of spaces)
  3. cannot use any of these symbols :’’’,<>?|()!@$%^&*^-+
  4. best practice to keep names lowercase
  5. avoid speacial names like “list” , “str” , “int” etc
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what is dynamtic typing?

A

you can reassigned variables to different data types

Example:

dog = 5

dog = “Jolly”

print(dog)

the code should output “Jolly”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. what is and symbol of the type function
  2. what does it do?
A
  1. type()
  2. it tells the type of data type of something

Example: type(5) #it should output int

type(“Bob”) #it should output str

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
  1. Define what a string is
  2. how do you write strings
A
  1. Strings are sequence of charaters using the syntax to either signle quotes or double quotes
  2. Example:“Bob”, ‘pizza’, “ I don’t do that “
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what is indexing in terms of strings?

A

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’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what is slicing in terms of strings?

A

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’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what is the lenth fucntion in terms of strings?

A

len()

it tells you the length of a string

Example: len(“bob”) #It should output 3

len(“I am”) #it should output 4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you create comments in python?

A

By using hashtags

Example: #this is a comment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

how do you make a string capitalize?

A

upper method

variable.upper()

Example: name = jason

cap_name = name.upper()

print(name) #should print jason

print(cap_name) #should print JASON

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

how do you make a string all lower case?

A

lower method

variable.lower()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

what is the split method and what does it do in terms of strings?

A

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”]

20
Q

What does the format method does?

A
21
Q

What are the 3 ways to perform string formatting?

A
  • 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.
22
Q

How does the f-string format looks

A
23
Q

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

A
24
Q

How do you create a list

A
25
Q

How to index and slice list?

A
26
Q
  1. Which method add an element into list?
  2. Which method deletes an item in list?
A
27
Q
  1. Which method reverse the order of a list?
  2. Which method puts a list in alphabetical order?
A
28
Q

How can we nest list?

A
29
Q

How do we create dictionary

A
30
Q

How to create keys from an empty dictionary

A
31
Q

How to nest dictionary

A
32
Q
  1. Which dictionary method return a list of all keys
  2. Which dictionary method return a list of all values
  3. Which dictionary method return tuples of all items
A
33
Q

How do we create a tuple

A
34
Q

Which two methods are mostly use in tuples?

A
35
Q

Why is main reason list differs from tuples?

A

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.

36
Q

How do we make a set in python

A
37
Q

What is the popular method use in sets?

A
38
Q

How do we make things Booleans ?

A
39
Q

How to write a text file

A
40
Q

How to open a text file

A
41
Q

How to read and close a text file

A
42
Q

Alternate way to open text file

A
43
Q

Alternate way to read text file

A
44
Q

What are the different modes in the text files

A
45
Q

Alternate way to append text file

A
46
Q

Alternate way to write file

A
47
Q
A