Table of Contents:
3.Concatenation(Using + operator)
1)Python Comments:
Python comments are used to add explanatory or descriptive text within the code.
Comments can be used to explain Python code.
Comments can be used to make the code more readable.
Comments can be used to prevent execution when testing code.
Here are some key points about Python comments:
Single-line Comments:
Single-line comments begin with the hash (#) symbol and continue until the end of the line. They are used to provide brief comments or annotations.
Example:
#This is single line comment print("Hello Python")
Comments can be placed at the end of a line, and Python will ignore the rest of the line:
Example:
print("Hello Python") #This is single line comment
Multi-line Comments:
Python does not have a specific syntax for multi-line comments like some other programming languages. However, you can use multi-line strings (enclosed in triple quotes) as a way to create multi-line comments.
'''This is multiline comment written in more than just one line''' print("Hello Python") (or) """This is multiline comment written in more than just one line """ print("Hello Python")
- Use comments to explain complex code, algorithms, or logic.
- Write clear and concise comments that provide meaningful insights.
- Avoid redundant comments that merely restate the obvious code.
- Maintain consistent formatting and indentation for comments.
- Update comments when modifying the code to keep them accurate and relevant.
- A variable name must start with a letter or the underscore character
- A variable name cannot start with a number
- A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
- Variable names are case-sensitive (age, Age and AGE are three different variables)
- A variable name cannot be any of the Python keywords.
#valid variable Names a=5 _b=10 a_b=30 m1=20 name="ram" NAME="mani" _a_b=25
#Invalid variable Names 1a=10 a b=20 $b=30 x-y=20
a=10
print(a)
a=10 a="Python" print(a)
#output
Python
a,b,c=1,2,3 print(a) print(b) print(c) #ouput 1 2 3
a,b,c=10 print(a) print(b) print(c) #ouput 10 10 10
print("Hello Mani")
a="I am" b=24 c="years old." print(a,b,c)
#output
I am 24 years old.
a="I am " b="24 " c="years old." print(a+b+c) #ouput: I am 24 years old.
a="10" b=5 print(a+b) #ouput: File "main.py", line 2, in <module> import user_code File "/tmp/user_code.py", line 3, in <module> print(a+b) ~^~ TypeError: can only concatenate str (not "int") to str