Page 275 - Ai_C10_Flipbook
P. 275
Some of the examples of valid identifiers are: Num1, First_Name, Value, Scores_FirstTerm.
Some of the examples of invalid identifiers are: 1stsubject, My name, #mobile, City&Code, and True.
Variables
Variable is a name given to a memory location to hold a specific value. It is just like a container that can hold any
type of data that can be changed later in the program. Variable has:
• A name that follows the rules of identifier naming conventions and is case sensitive.
• A value that can be integer, float, string, boolean, etc.
Unlike other programming languages, variables in Python are not created before. They are created automatically
when a value is assigned to it using the assignment operator (=) Value to be assigned is always on the right side
of the equal to. A variable assigned with a value of one type can be re-assigned a new value of a different type as
shown below:
[1]: a=9
print(a)
a="Orange"
print(a)
9
Orange
There are different ways of assigning values to different variables in Python:
• Method 1: Assigning different values to different variable in different lines.
[1]: rollno = 5
strength = 10.5
name = "Amita"
• Method 2: Assigning different values to different variable in the same line.
[1]: rollno, strength, name = 5, 10.5, "Amita"
• Method 3: Assigning same values to different variables in the same line.
[1]: marks1 = marks2 = marks3 = 45
Data Types
Data types specify the kind of a value a variable can store. It helps us to identify the kind of operation that can
be performed on that specific data type. Every value in Python has a data type.
Data Types
Numbers None Boolean Sequences Sets Maps
int float complex string list tuple Dictionary
Advance Python (Practical) 273

