Page 93 - Touchcode_C7_Flipbook
P. 93
In Python, we do not need to specify the type of variable because Python is a dynamically
typed language and it identifies the variable type automatically. Let’s understand this with
the help of the given examples.
num = 0.4
_price = 30.3
TOTAL = round(_price * num,2)
print(TOTAL)
Declaring and Initializing a Variable
In Python, variables are declared and initialized at the same time in the following way:
a = 10
b = 20
print (“a=”, a)
print (“b=”, b)
You must follow the given rules while creating and naming the variables:
A variable name must start with a letter or underscore character.
A variable name cannot start with a number.
A variable name can only contain alphanumeric characters (all the letters of the alphabet
and numbers) and underscores (_).
Variable names are case-sensitive.
Variable names cannot contain any special character or symbol.
DATA TYPES
A data type specifies the type of value a variable can contains. For example, a person’s
name must be stored as a string value whereas the person’s age must be stored as an
integer. Data types in Python are: int, float, string, etc.
COMMENTS IN PYTHON
Comments in Python can be used to explain parts of the code. It can also be used to
hide the code as well. Comments enable us to understand the way a program works.
In python, any statement starting with # symbol is known as a comment. Python does
not execute comments. Comments are not a part of the program, but they do enhance
the interactivity of the program and make it readable. Python supports two types of
comments: Single line comment and Multiline comment.
Single Line Comment
In case, a user wants to specify a single line comment, then comment must start with the
symbol #.
More on Python
More on Python 91
91

