Python 1 Flashcards
What are the primitive types?
int - hole numbers
float - floating numbers (w/coma)
bool - booleans values
str - strings (text)
What’s does ^, inside a parenthesis mean?
^ - text will be centralized
< - text will be to the left
> - text will be to the right
What’s does the x and 20 inside a parenthesis mean?
The x is the symbol u want to appear and the 20 the number os spaces it will occupy.
How can u make a text continue on the same line?
print(‘~~~~~~~~~~~~~~’, end=’ ‘)
How can u ‘‘break a line’’?
print(\n~~~~~~~~~)
How can u make a list on Python?
a = one b = two list = [a, b]
What’s the function on len()?
To read how many characters are in the line.
How can u use ‘in’?
u can use: ‘word’ + in + a (phrase), it will tell if there is that word in the line.
How can u use ‘count’? count(a, b, c)
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 can u use find, replace, capitalize and title?
find.(‘letter/phrase’) will find it
replace(‘what u want to replace’ , ‘what will be the replacement’)
print(zzzzzzzzzzzz).capitalize()
print(zzzzzzzzzzzzzz).title()
What does the split command do? How to use it?
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 can u read the first name of something?
(phrase name - find(‘ ‘))
u will eliminate the first space “find” command finds.
What will happen if u put the r/l before a command?
It will apply on the right or in the left side of the formula.
ex = r.strip()
What’s the symbols of a commentary?
’'’PHRASEEEE
AAAAAAAA’’’ ( 3 quotes)
What’s the command to import todays date?
from daytime import date
date.today().year
What’s the range of colors on style/text/background?
style = 0/1/4/7 text = 30 - 37 background = 40-47
How can u convert to binary/octal/hexdecimal?
bin()
oct()
hex()
What happens with the last number inside the range of a for function?
It will decrease one, so add one to the range.
u want 12 = for c in range (1, 13)
how can u count backwards on a for function?
for c in range(1, 12, -1)
Add the minus one at the place where the order of numbers is achieved.
By using an accumulator, how can u sum the numbers that you’ve typed?
s = 0
for —–
a = int(input(‘Type a value: ‘))
s += a
Are the 3 values of the for ex(a, b, c) all alterable?
yes, by formulas and inputs.
Whats an accumulator?
A function that lets u make counts inside for and while commands.
How can u re-use a line inside a while or for comands?
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
Is it possible to put a if inside a print function?
Yes, actually u can literraly put any function inside other (while, if, etc)
What does the count function stands for?
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)
Can u make a more than 1 accumulator on the same line?
yes, if they are given the same initial number.
ex - a = b = 0
How can u lock the answers of the user on a while/for function?
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.