Variables and print function:
A variable is nothing but it allocates the memory space and holds the values.
Syntax:
variable_name = value
print('print statement', variable_name) or
print("print statement", variable_name)
Example:
a = 5
print('value is:', a)
print("a value is:",a)
output:
Another form of varible declartion:
Example:
a,b,c=2,3,5
The above example describes a=2,b=3, and c=5.
Escape sequence:
Escape sequence
Description
Example
Output
\n
New
line or next line
Print(“Hai! \n I am Sabrina.”)
Hai!
I am Sabrina.
\t
Horizontal
tab(one tab space)
Print(‘Hai\t Hello’)
Hai hello
\’
Display
single-quotes
Print(‘I don\’t know’)
I don’t know
\”
Display
double-quotes
Print(‘/”Hey/”’)
“Hey”
\\
Print
slash
Print(‘a\\b’)
a/b
variable_name = value
print('print statement', variable_name) or
print("print statement", variable_name)
a = 5
print('value is:', a)
print("a value is:",a)
output:
Another form of varible declartion:
Example:
a,b,c=2,3,5
The above example describes a=2,b=3, and c=5.
Escape sequence
|
Description
|
Example
|
Output
|
\n
|
New
line or next line
|
Print(“Hai! \n I am Sabrina.”)
|
Hai!
I am Sabrina.
|
\t
|
Horizontal
tab(one tab space)
|
Print(‘Hai\t Hello’)
|
Hai hello
|
\’
|
Display
single-quotes
|
Print(‘I don\’t know’)
|
I don’t know
|
\”
|
Display
double-quotes
|
Print(‘/”Hey/”’)
|
“Hey”
|
\\
|
Print
slash
|
Print(‘a\\b’)
|
a/b
|
Comments:
It describes what's going on inside a program, so that person looking at the source code does not have a hard time figuring it out.
Types of comments:
(i)Single line comments:
Using Hash symbol #
Syntax:
#Statements
Example:
#This is the addition program
(ii)Multiline comments:
Using single or double-quotes.
Syntax:
'''Set of Statements or something'''
Example:
'''This program having some fault
a=d
print(a)'''
Input function:
This input function is used to value get from users.
Syntax:
Syntax:
variable_name = data_type(input("Senetence"))
Example:
a =int(input("Enter first number"))
b =int(input("Enter Second number"))
print("The addition value is:",a+b)
output:
variable_name = data_type(input("Senetence"))
a =int(input("Enter first number"))
b =int(input("Enter Second number"))
print("The addition value is:",a+b)
output:
Multiple Input value get from user:
Using Split() function.
Syntax:
No.of.variable_name = input("Senetence").split()
Example:
a,b,c =input('enter values').split()
print("The addition value is:",int(b)+int(c))
print(a,b,c)
output:
No.of.variable_name = input("Senetence").split()
a,b,c =input('enter values').split()
print("The addition value is:",int(b)+int(c))
print(a,b,c)
print(a,b,c)
output:
No comments:
Post a Comment