*Introduction to python:
Python is a programming language used to create software & it is easy to learn.
Guido Van Rossum was the founder of the python language. He liked a tv serial python. Thus he named this language python.
* print ( ) function:
It is used to print something on the screen.
E.g. print("Hello World")
or
print('Hello World')
Output: Hello World
* String :
Collection of characters inside the "double quotes " or 'single quotes'
Note: You can use 'single quotes' inside "double quotes" or "Double quotes" inside 'single quotes' .
* Escape sequence:
Escape sequences allow you to add special characters in strings. To do this, simply add backslash ( \ ) before the character you want to escape. Table for escape sequences are :
Eg. print("My name is \n Pankaj Kumar" )
Output:
My name is
Pankaj Kumar
Backspace(\b ) command is used to delete a word.
E.g. print("hell\blo")
Output: hello ( But in input there was three lll , it is the magic of the backspace escape sequence.)
* Comment:
A comment is a text that doesn't affect the outcome of a code, it is just a piece of text to let someone to know that what you have done in a program.
# symbol is used for comment anything.
E.g.
# This is a comment
print("Pankaj Kumar")
Output:
Pankaj Kumar
* Exercise question:
print output as : \" \n \t \'
Solution:
print(" \\\" \\n \\t \\\' ")
* Raw string:
The raw string is created by prefixing a string with r or R . Python raw string treats backslash ( \ )as a textual character. This is useful when we want to have a string that contains backslash & don't want to be treated as an escape character.
Eg. Input:
print(r"\" \n \t \' ")
Output: \" \n \t \'
* How to print Emoji:
All Emoji have different commands. Command of some emoji are:
Eg: print(" \ U0001F602")
* How to use python as a calculator:
* In the last operation i.e. ** means the power of something. Eg. 2** 3 = 2^3 = 8
* If we want the root of any digit. Eg. I want the root of print(2** 0.5) = 1.41421356237
But I want to take a round off the value of under root 2. Then we have to use round off function:
print (round(2**0.5,4))
Output: 1.4142
* BODMAS rule plays an important role in the calculation.
Here B= Barakat, O = order, D = Division, M = Multiplication, A = Addition, S = Subtraction.
* \\ will print as \ in output. & \\\\ will be print as \\ double backslash in output.
1. Python language
Reviewed by Endless Technology
on
06:19
Rating:
No comments: