Page 429 - AI Ver 3.0 class 10_Flipbook
P. 429
• Using Braces {} (for dictionaries or sets): Similar to parentheses, curly braces can be used to break long
dictionary or set definitions across lines.
[1]: my_dict = {
'name': 'John',
'age': 30,
'city': 'New York'
}
• Using Square Brackets [] (for lists): You can also break a list definition or list comprehension into multiple
lines using square brackets.
[1]: my_list = [
1, 2, 3, 4,
5, 6, 7, 8
]
• Using the Continuation Character (\): A backslash (\) at the end of a line indicates that the statement continues
on the next line. This method is used for breaking any statement into multiple lines.
[1]: result = 11 + 15 + 148 + \
154 + 87
Multiple Statements
Multiple statements mean more than one statement in a single line. This can be done by separating the
statements using semicolons (;).
[1]: a=5; b=10; c=a+b; print(c)
15
Comments
Comments are used to increase the readability of the code. We use it to give proper understanding of the code in
simple English statements. They are completely ignored by the Python interpreter and do not display or affect the
output of the code. It is always a good practice to add comments in your code so that if anybody in future wish to
understand or modify your code then through comments it become easy to know what you have written in a code.
In Python we can give two different kind of comments. Let us discuss about them.
Single Line Comments
Starts with a hash symbol ‘#’ followed by the text to be written as a comment that lasts till the end of the line.
[1]: # This creates variables for storing marks
english=93
maths=92
# Calculating the programs
c=(english+maths)/2
Multiline Comments
When writing multi-line comments, we begin the comment with three single quotes ''' or three double quotes
""", followed by the comment text spread across multiple lines. The comment ends with the same three single
or double quotes ''' or """.
Advance Python (Practical) 427

