Python Data Type
Python Standard Data Type
Mutable and Immutable data type
Difference of Mutable and Immutable:
Mutable Data type can be updated; Immutable Data type cannot be updated.
Types | Data Type |
---|---|
Mutable | List, dictionary, set |
Immutable | Numeral, String, Tuple |
Examples:
1 | a = [1,2,3] |
Numeral
Numeral data type includes: Integer, float
Some important operators:
- % : called the modulo operator 69 % 12 == 9
- // : called the floor division operator 69 // 12 == 5
Some methods: - int( ) : return the integer part in int type, no round int(1.6) == 1
- float(): return the decimals in float type, float(1) == 1.0
We can use these two function to convert string. And you will get error if the string does not contain numeric characters. What’s more you can’t use int to convert a string of decimals
1 | '123' sval = |
Decimal computation problem
String
- String has length
fruit = "banana print(len(fruit)) Output: 6
- Slicing Strings
s = "Monty Python" print(s[0:4]) output: Mont
List
Dictionary
Tuple
Set
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Comment