Python 1 Flashcards

1
Q

What are the primitive types?

A

int - hole numbers
float - floating numbers (w/coma)
bool - booleans values
str - strings (text)

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

What’s does ^, inside a parenthesis mean?

A

^ - text will be centralized
< - text will be to the left
> - text will be to the right

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

What’s does the x and 20 inside a parenthesis mean?

A

The x is the symbol u want to appear and the 20 the number os spaces it will occupy.

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

How can u make a text continue on the same line?

A

print(‘~~~~~~~~~~~~~~’, end=’ ‘)

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

How can u ‘‘break a line’’?

A

print(\n~~~~~~~~~)

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

How can u make a list on Python?

A
a = one
b = two
list = [a, b]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What’s the function on len()?

A

To read how many characters are in the line.

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

How can u use ‘in’?

A

u can use: ‘word’ + in + a (phrase), it will tell if there is that word in the line.

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

How can u use ‘count’? count(a, b, c)

A

phrase + .count(‘a’, 0, 12), which means:
a = the letter u want to find
0= the character u will start it
12= the last character u want to check(which will be 11)

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

How can u use find, replace, capitalize and title?

A

find.(‘letter/phrase’) will find it
replace(‘what u want to replace’ , ‘what will be the replacement’)
print(zzzzzzzzzzzz).capitalize()
print(zzzzzzzzzzzzzz).title()

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

What does the split command do? How to use it?

A

It separates the words typed in groups (using the space as filter).
U type a phrase, then make another command spliting it, then you print the split + the group u want.
a = ‘Hello there’
b = a.split()
c = print(b[0/1])
the [ ] indicates which group u want to select, starting by 0.

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

How can u read the first name of something?

A

(phrase name - find(‘ ‘))

u will eliminate the first space “find” command finds.

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

What will happen if u put the r/l before a command?

A

It will apply on the right or in the left side of the formula.
ex = r.strip()

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

What’s the symbols of a commentary?

A

’'’PHRASEEEE

AAAAAAAA’’’ ( 3 quotes)

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

What’s the command to import todays date?

A

from daytime import date

date.today().year

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

What’s the range of colors on style/text/background?

A
style = 0/1/4/7
text = 30 - 37
background = 40-47
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How can u convert to binary/octal/hexdecimal?

A

bin()
oct()
hex()

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

What happens with the last number inside the range of a for function?

A

It will decrease one, so add one to the range.

u want 12 = for c in range (1, 13)

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

how can u count backwards on a for function?

A

for c in range(1, 12, -1)

Add the minus one at the place where the order of numbers is achieved.

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

By using an accumulator, how can u sum the numbers that you’ve typed?

A

s = 0
for —–
a = int(input(‘Type a value: ‘))
s += a

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

Are the 3 values of the for ex(a, b, c) all alterable?

A

yes, by formulas and inputs.

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

Whats an accumulator?

A

A function that lets u make counts inside for and while commands.

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

How can u re-use a line inside a while or for comands?

A
just using the same letters used on the questions made previously.
a = zzzz
b = xxxx
while True
if c == 2
a = hhhhh (same fuction as the a)
b = lllllllllll
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Is it possible to put a if inside a print function?

A

Yes, actually u can literraly put any function inside other (while, if, etc)

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

What does the count function stands for?

A

It calculates the total of times an answer has been given and the character it should start counting in a while or for function. (not a number, a position)

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

Can u make a more than 1 accumulator on the same line?

A

yes, if they are given the same initial number.

ex - a = b = 0

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

How can u lock the answers of the user on a while/for function?

A

By defining a input with a space inside::
v = ‘ ‘
Inside the while put the answer with a space in the quotes.
then another while –> while + the input + not in + the answers u want altogether: + the questions below it.
It will make it ask again and again until the user answers correctly.

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

What is the break command?

A

The break command will stop a while condition once it have met the flag, which will be defined by an if function, it is commonly used with the while True infinite form.

29
Q

What are the f-strings? and how do u use it?

A

A function that allows u to replace the .format by a shorter version.
u use it like = print(f’zzzzzzz {a}’)
putting an if before the quotes and then the plugin inside the keys, then just it all.

30
Q

What’s a program?

A

A determined sequence of instructions.

Written in a special text-file type (language)

31
Q

What’s the use of the parentesis?

A

To separate parameters from a function.

32
Q

What’s a parameter? give an example.

A

Its a value passed to a function, like the text inside a print.
text = value
print = function

33
Q

What are variables used for?

A

They are used to maintain values, and to give name to an area of the computer which we maintain data.

34
Q

What are the basic operators that Python supports?

A

Not, and, or.

35
Q

What is a string?

A

A chain of characters.

36
Q

What is a tuple? how to create one?

A

It’s a function that groups any numbers of other functions inside of it, making the program much lighter, allowing a call to isolated itens inside of it.
tuple = ‘apple’, ‘pear’, ‘watermelon’, ‘italian’

37
Q

How do u recall the variables inside the main on a tuple function?

A

U have to open the keys and type the numbers equivalent to the character group that it is related, it starts in 0 and goes divided by the space bar.
Print(a[0:5])
Remembering that if u put it go until the 3 character it’ll only go until the two.

38
Q

What does the ‘enumerate’ function do? and how to use it.

A

It enumerates the items in a group, starting by zero.
u must create two variables.
for + name1, + name 2 in enumerate(name of the tuple)

39
Q

What is the function of ‘sorted’ and how to use it?

A

It will organize the items in a phrase in a alphabetical order.
print(sorted(name of tuple))

40
Q

What is the function of ‘index’ and how to use it?

A

It tells the position of element inside a tuple.

print(name_of_tuple.index(‘a’))

41
Q

What is the function of ‘del’ and how to use it?

A

Will delete anything in Python.

del(put_the_item)

42
Q

What do u need to do the cutting? and what does these symbols represent?

A

Two number inside a key [ : ] separated by a : symbol, which indicates from where to where u want to cut, remembering that the final position is never counted.

43
Q

Can u use negative numbers to represent position in a cutting?

A

Yes, by considering the last character of the phrase as being the -1, then -2 and so on.

44
Q

The line with the condition (if) is executed even if the condition is not met?

A

Yes.

45
Q

What does it mean when there is a : in Python?

A

It means there will be a line block.

46
Q

What happens when we attribute a new value to a condition?

What can u do about it?

A

The last value is replaced.
you can create a variable (s = 0) to receive a copy of the condition, so it will keep the first value (if u need to use it)

47
Q

What’s the function of max/min and how can u use it?

A

Its to select the highest (max) and lowest (min) number in a phrase, string or tuple.
max/min + phrase (tuple)

48
Q

What is to nest a condition?

A

To put and if/elif inside another if/elif.

49
Q

How can u make an input inside a tuple?

A

a = (int(input(‘Type a number: ‘)), int(input(‘Type another one: ‘)))
one extra parenthesis initiating the phrase and one extra closing it.

50
Q

Are lists mutable?

A

Yes, u can alter them any time.

51
Q

What’s the command append and how to use it?

A

A command that puts elements at the end of a list (after last element).
name + .append + (‘element’)

52
Q

What’s the command insert and how to use it?

A

This command will add an element at any place of the list.
name + .insert + (0, ‘element’)
0 = the position of the character

53
Q

3 commands to remove elements from lists?

A
del
del.list + [number of positions}
pop
list.pop + [number of position]
remove
list.remove ['name of element']
54
Q

What is a counter?

A

A variable used to count the numbers of ocurrencies of an event.

55
Q

What happens if the starting condition is already false?

A

The block will not be inniciated.

56
Q

How to create a list of numbers using list?

A

a = list(range(0,11))

57
Q

What’s the command that organize numbers? and how to reverse it?
Can it be added inside of keys?

A
  • sort
    name + .sort()
    reverse order - name + .sort(reverse=True))
    No it can’t
58
Q

How to insert values directly into a list?

A

v = list[ ]
for count in range (1,4);
v.append(int(input(‘Type a value: ‘)))

59
Q

How to insert values directly into a list (without writing inside) ?

A

v = [ ]
v.append(int(input(‘Type a value: ‘)))
can be combined with for or while.

60
Q

What’s a connection of lists?

A
Its when you make a list equal to another by using ' = ', and everything you do to one, will be done to the other as well
a = [2, 5, 7] 
b = a
b [2] = 8 
a = [2, 5, 8]
61
Q

What’s the difference between a counter and a accumulator?

A

The difference is that the counters have the value added as a constant, and in the accumulators it is variable.

62
Q

Can you write functions inside an f-string?

A

Yes.
x = 10.6
(f’int = …..{int(x)}

63
Q

Can f-strings be used as strings of multiple lines?

How to do it?

A
Yes.
Using 3 quotes.
f """
int(input('The price is: {}.'))
str(input('And can be found {}.'))
"""
64
Q

What does the /n stands for?

A

A break of the line, it will basically put lines one below the other.

65
Q

What’s the function of the ‘range’ command?

A

To generate a list of numbers excluding the last you you’ve typed.
range(1, 10) —- > will generate 1 until 9

66
Q

How to transform a generator into a list?

A

Use the function ‘list’:

list(range(0, 10)

67
Q

What does the ‘enumerate’ function do?

A

Generates a tuple which the first value is the index and the second is the element of the list being enumerated.

68
Q

Can you put a str, int and float inside the same list?

A

Yes.

a = [yes, 10, 0.5]

69
Q

What is the bubble sort method?

A

It consists on comparing two elements each time, if the value of the first element is bigger than the second, they change their position until the end of the list.
It also positions the biggest element at the last position of the list.
It also need a marker to indicate when it has reached the end of the list changing an element or not.