- Get link
- X
- Other Apps
Integer and Float
• Variables can hold values of different types called data types. Some of the commonly used data types in python are integer, float, bool, strings, lists, tuples, dictionary, sets, etc
• The data type of a variable is dependent on the value of the variable. For example, if the value of the variable userAge is 18 i.e
userAge = 18
Here the data type of the variable is an integer.
• For float data type the value of the variable should be a decimal. For example, if you create a variable for the percentage of students in class studentPercentage with a value 78.5 i.e
studentPercentage = 78.5
Strings
• A string data type is used to store textual information into a variable.
• To store the value of a string data type, we need to put the value inside double quotes 11
" or single quotes ''. For example
schoolName = "Bright International"
characterName = 'Eva'
• Boolean data types are used when the value can be either true or false.
• For example, there are two possibilities for the question "Do you like to play chess? Yes or no. To make a boolean variable we will set the value as True (for yes) and False (for no).
likeChess = True
here likeChess is a boolean variable with True as the value.
Bool and Lists
• Lists are used to store multiple items in a single variable. For example, Name of three cars can be stored as follows.
carNames = ["Thar", "Swift", "Alto", "A
0
Here we are storing names of 5cars in 1 list.
• The values are separated using comma. Here we are storing string values, hence we have used quotes. If we want to store numbers, we can do it without quotes. For example:
userAge = [10,12,14,15,16]
Dictionary
• Dictionary data type is used when we need to store details of something. It is a collection of pairs.
• For example, to store the details of a car like name, colour, model, etc we will be using dictionary data type. The details of the car will be stored as follows.
detailsOfCar={ "carname": "audi S5",
Tuples
• Tuples are similar to lists with one distinguishing factor that the values in a tuple cannot be modified.
• Tuples are used when we want to store values that should not be changed during program execution. For example: Months of the year can be store in tuples as follows:
monthsOfTheYear = ("Jan", "Feb", "Mar"
- Get link
- X
- Other Apps
Comments