Input/Output, Comments, Variables, Rules for variables.
Input/Output are used to take input from the user and print the output
Syntax: variable_name = input()
Ex: a = input(a)
For best practice use message ex: a = input(“Enter your name : “)
Rules:
- By default the input() type is string.
- In order to take different types of input, below is the syntax.
syntax : a = int(input(a)), a = float(input(a)) etc..
For output we use print() keyword to display messages, variable values etc
Syntax: print(a)
Ex:print(“Hello world”)
print(“The value of a is : “)
Comments
In python we have two type of comments.
- Single line comments
- Multiline comments
Syntax:
Single line comments : # is used to make single line comment
Multipline comments : ‘’’ 3 quotes are used to make multiline comments
Best practice: Comments make code easy to read. Try to include comments in every peice of code.
Example: # This is a single line comment
“”” This is a multiline comments
We can use second line aslo “””
Variables
Variables are used to store values.
Example : a = 10
Here ‘a’ is a variable which store value 10.
Variables can store any type of data.
Variables Rules
- Variable should start with a alphabet and underscore(_)
- Variable should not start with special characters, keywords,numbers, double underscore.
Example: a, _a
Best Practice: Start variable with alphabet and use underscore in between for bet understanding
Hope, this piece of document helps with the python basics.