Fichas
Python commands
Fichas del conjunto (35)
- 1Package installerpip install
- 2Write something in the consol(easy way)print(str("x"))/print(int(x))
- 3How to check what type a command is?for Ex.:type("x") ---> class str
- 4What is the output of: type("Hello!")class 'str'
- 5What is the output of: type(10)class 'int'
- 6What is the output of: type((10, 20, 30))class "tuple"
- 7What is the output of: type([10, 20, 30])class 'list'
- 8What's the key diffrence between of a 'tuple' class and a list?Tuples = immutable
List = mutable - 9For what stands 'int'? (And give an example)int = integer
For ex.: −3, −2, −1, 0, 1, 2, 3,...
No integers are for ex.:- 1.43, 1 3/4, 3.14,... - 10Is 0 an integer?Yes
- 11Example for float numbers:133.5, 2897.11, 30.0, 3,8
- 12What does this do?: for i in range(10): print(i)output:
0
1
2
3
4
5
6
7
8
9 - 13What does this do?: for i in range(10,20,2): print(i)10
12
14
16
18
--> 2 steps (Begins at 10) - 14how to round sth.?round(number, digits)
- 15What doe this do?: x = round(20.7907, 2) print(x)output:
20.79 - 16How to create an user input?x = input("Userinput")
- 17How to find the length of an object?len(x)
- 18What does this do?: x = "Hello World" print(len(x))output:
11 - 19What does this do?(user wrote Hey): x = input("Write a word: ") print("You input is "+str(len(x))+" letters long")Output:
"Your input is 3 letters long" - 20Would this work?: x = input("Write a word: ") print("You input is "+len(x)+" letters long")No, len(x) is an int. So it hast to be transformed to a string (with str()).
Correct code:
x = input("Write a word: ")
print("You input is "+str(len(x))+" letters long") - 21How to create a loop? (simple way)With 'for' or 'while'
- 22Easy way to create an "infinitive" loop:while True:
.... - 23What's the output?: x = ["B","Hello", "Made by MRK", "C"] for k in x: print(k)output:
B
Hello
Made by MRK
C - 24Would this code work?: x = ["B","Hello", "Made by MRK", "Cool", 1, 2] for p in x: print(p)Yes, althoug there is an int, it has no inpact
- 25What's the output for this code? x = ["B","Hello", "Made by MRK", "Cool", 1, 2] for i in x: print(x)['B', 'Hello', 'Made by MRK', 'Cool', 1, 2]
['B', 'Hello', 'Made by MRK', 'Cool', 1, 2]
['B', 'Hello', 'Made by MRK', 'Cool', 1, 2]
['B', 'Hello', 'Made by MRK', 'Cool', 1, 2]
['B', 'Hello', 'Made by MRK', 'Cool', 1, 2]
['B', 'Hello', 'Made by MRK', 'Cool', 1, 2]
--> in the list 'x' are 6 values: so x will be get printed (my english is fucked up btw xD) - 26How to check if a value is a string?for example:
x = "MadebyMRK"
print(str.isalnum())
Output:
True - 27What's the output: x = "Made by MRK" print(x.isalnum())Output:
False
(There is a 'space' between the word--> no string) - 28How to capitalize a function?for example:
x = "hey"
print(x.capitalize()) - 29What's the output? txt = "My Name is Maruko" x = txt.find("is") print(x)The output is: 8
--> The str "is" is at the 9th "position" of the string --> computer always begin at the position "0" ---> just count the positon and do -1 ---> 9 - 1 = 8 - 30What's the output? txt = "My Name is Maruko" x = txt.find("MRK") print(x)The output is: -1
--> If the computer isn't able to find a str that matches with your value, it will always respond with -1 - 31How to count sth.?with the count function
- 32What's the output: string = "Emma is good developer. Emma is a writer" print("Given sentences: "+string) print("The Name Emmea apperas: "+str(string.count("Emma"))+" times!")The output:
Given sentences: Emma is good developer. Emma is a writer
The Name Emmea apperas: 2 times! - 33How to center sth. (Space missing space on each side)With:
str = "x"
MRK = str.center(5, "-")
print(MRK)
Output:
--x-- - 34How to remove an elemnt from a specified position in the list?pop()
- 35How to sort elemnts in a list?sort()
Información
- Descripción
- Hey, I prepared for every (at least I tried for every command °-° ) function a github python file. Feel free to review these commands and to give some feedback (I created them to train for myself actually). Cya and have fun! https://github.com/Maruuuko/python_command_index_cards
- Creado por
- Maruuuko W
- Visitas
- 7
- Valoración