Mapa mental
Python
Conteúdo do mapa
Python
A string is a piece of text put in speech marks
- money = 15 print ("You have £"+str(money))
- money=15 is an integer, as there aren't any speech marks so the module won't work, so you put str in front of money in brackets, so the computer thinks it's a string, so it'll work
- This is casting
- value = "3" print (value + value) value = int(value) print (value + value)
- value becomes an integer as putting int( in front of (value) it makes it an integer, and since the value is 3, and since the equation is Value+value it is 3+3 which is 6
- value = "3" print (value + value) value = int(value) print (value + value)
- E.g. print("Hello World")
- money = 15 print ("You have £"+str(money))
A float is a decimal number
An integer is a whole number
Lists
- thislist=["apple","banana","cherry"]
- apple=0,banana=1,cherry=2
- print(thislist) meaning when you print it,it will print apple,cherry,banana
- print(this list[1],will print banana,as banana is 1,print(this list[2]),will print cherry as cherry is 2,etc
- if you put print(thislist[1]="blackcurrant" then print(thislist) it will print the list but instead of the list being apple,banana,cherry it will print apple,blackcurrant,cherry as you changed the value 1 to blackcurrant instead of banana
- if you put print(x) after print(thislist) it will print each item one by one
- putting this list.remove("banana") then print(thislist)will print out the list,but will remove banana from it
- thislist.append("orange") adds orange to the list
- thislist=["apple","banana","cherry"]
Function
- def my_function(): creates the function called my function
- To call a function you do def my_function(): then print("hello from a function) then my_function() for the output to be Hello from a function
- Parameters
- To pass info from a function you use this
- def my_function(fname): then print(fname + " Refsnes") then my_function("Emil") my_function("Tobias") my_function("Linus")
- this will print Emil Refsnes,Tobias Refsnes and Linus Refsnes
- It prints this out as in the brackets you put fname then putting( fname + "Refsnes") will make fname Refsnes and putting my_function("Emil") will put the name Emil in front of Refsnes, so they it becomes Emil Refsnes
- this will print Emil Refsnes,Tobias Refsnes and Linus Refsnes
Concatenation
- a = "Hello" b = "World" c = a + b print(c)
- when you print(c),since c is equal to a+b a representing Hello and b representing World it would equal hello world
- a = "Hello" b = "World" c = a + b print(c)
Informações
- Descrição
- Year 9 Computing Mapa Mental sobre Python, criado por Gbubemi Arenyeka em 01-10-2019.
- Criado por
- Gbubemi Arenyeka
- Visualizações
- 18
- Avaliação