Python Revision - Section I - Data Types
Python Revision - Section I - Data Types
Numbers
In Python we just have: integers and floating-point numbers.
Strings
Immutability: Once a string is created, the elements within it can not be changed or replaced.
- Methods:
1 2 3
s.upper() s.lower() s.split()
Print Formatting:
1 2
print("bla bla {}".format("ble ble")) #=> prints 'bla bla ble ble' to STDOUT.
We can also write print formatting like this:
1 2 3
text = "ble ble" print(f"bla bla {text}") #=> prints 'bla bla ble ble' to STDOUT.
Lists
Methods:
1 2
l.append() l.pop()
Dictionaries
Methods:
1 2 3
d.keys() d.values() d.items()
Tuples
Immutability: Use tuples to present things that shouldn’t be changed, such as days of the week.
Methods:
1 2
t.index("value") t.count("value")
- Tuples doesn’t have an append method.
Sets
Unique elements: we can get a list of unique element calling the set function.
1
set(list)
I hope it will be helpful to you and if there’s any questions or something else, please, feel free to contact me.
Forte Abraço
This post is licensed under CC BY 4.0 by the author.