Let's take a look at some of them.
1. Strings (str): This could be any character surround via by a single or double quote. state = "California"
2. Integer (int): zip=92129
3. Float (float): latitude=34.073620
4. Boolean (bool): True or false You_Rich=True
5. List (list): Value can be of any data type in a []. home =["Beverly Hills", "Mansion", "Penthouse"]
6. Dictionary list of key value pairs in a {}. phone_contact ={"John": "555-5555", "Gina": "555-5252", "Lisa": "555-5255"}
7. Set (set): Collection of unique elements. set(vendors)=>['att', 'verizon', 'tcox']
8 Tuple: (tuple) Immutable sequence of values (): address=(10, 10, 20, 20)
Immutable in python = You can't change the value.
Other types such as Strings, List, Dictionary are all mutable. You can change these values .
Example of immutable values such as social security #. You are assigned one social security #. That value will never change. You can change your name but your SSN will be the same.
Determining types.
type(name of variable)
Example:
>>> state = "California"
>>> type(state)
<class 'str'>
>>> type(zip)
<class 'int'>
>>> type(latitude)
<class 'float'>
Python operators
Python has the different operators which allows you to carry out required calculations in your program.
+ , - and * works as expected, remaining operators require some explanation.
similarly you can use - , % , // , / , * , ** with assignment operator to form augmented assignment operator.
Source: https://thepythonguru.com/python-numbers/
Great Video to watch regarding Data Types.
No comments:
Post a Comment