In Python, we use the hash (#) symbol to start writing a comment.
Tuple Assignment
•
Tuple is a sequence of items of any type.
•
Syntactically tuple is a comma separated list of values.
•
Conventionally tuples are enclosed within the parenthesis.
•
The main differences between lists and tuples are: Lists are enclosed in
brackets
([
]) and their elements and size can be changed, while tuples are enclosed in parentheses
(( )) and cannot be updated.
•
Tuples can be thought of as read-only lists.
•
For example: The tuple can be created as follows:
>>>
student = ('AAA',96, 'Std_X')
>>>
print(student)
(AAA', 96, 'Std_X')
>>>
print(student[0])
AAA
>>>
print(student[1:3])
(96,
'Std_X')
•
Python has a very powerful tuple assignment feature that allows a tuple of
variables on the left of an assignment to be assigned values from a tuple on
the right of the assignment.
• For example -
Review Question
1. Explain the tuple
used in Python.
Comments
•
Comments are the kind of statements that are written in the program for program
understanding purpose.
•
By the comment statements it is possible to understand what exactly the program
is doing.
• In Python, we use the hash (#) symbol to start writing a comment.
•
It extends up to the newline character.
•
Python Interpreter ignores comment.
•
For example # This is comment line print("I love my country")
•
If we have comments that extend multiple lines, one way of doing it is to use
hash (#) in the beginning of each line.
For
example
#This
is
#another
example
#of
comment statement
Problem Solving and Python Programming: UNIT II: Data Types, Expressions, Statements : Tag: Engineering Python : Python Programming - Tuple Assignment, Comments
Problem Solving and Python Programming
GE3151 1st Semester | 2021 Regulation | 1st Semester Common to all Dept 2021 Regulation