Mapa mental
Revision: commands and strings
Contenido del mapa
Revision: commands and strings
Strings
- Writing as str in python.
- A contiguous collection of characters surrounded by single or double speech marks.
- Comes up as green speech marks in python.
- To count a certain number of strings, we always start from zero.
- h = "cheesecake" print(h[0])
- This will print the first letter of the variable h which would be "c"
- h = "cheesecake" print(h[0:5])
- This allows us to print multiple letters of the varibale h
- strip( ) command
- If we have a string with spaces either side of the speech marks, we can remove these using the strip command.
- This can be also used to take away certain characters in a string. (Note, this can only be done when there are no spaces between the string and the speech marks.)
Upper ( ) and lower ( ) command
- print(h.upper()) print(h.lower())
- Upper prints the variable h in capitals.
- Lower prints the variable h in normal lettering.
- print(h.upper()) print(h.lower())
len ( ) command
- print(len(h))
- prints the length of a variable.
Replace( ) command
- (h.replace('c' , 'h'))
- This would print hceesecake
- (h.replace('c' , 'h'))
split ( ) command
- print(h.split(","))
- This would print the variable h which I have now changed to "love cheesecake") This would print {" love "cheesecake"}
- print(h.split(","))
For loops
- for x in banana: print(x)
- This print banana like this: b a n a n a
- for x in banana: print(x)
Información
- Descripción
- Mapa Mental sobre Revision: commands and strings, creado por Harriet Leplar el 14/05/2019.
- Creado por
- Harriet Leplar
- Visitas
- 0
- Valoración