Professional Documents
Culture Documents
Line Commands:
pwd : Print Working Directory
ls
clear
cd f:\\
mkdir "new python course"
mkdir complete_course
mkdir command practice 2 --> without "" it will create 2 seperate folders
touch new_doc.txt --> to create the file
cd .. --> to go back one step
rm file_name --> to delete the file
rm -rf --> remove folder (rf=recursive folder)
mv file_name.py filenew_file.py --> rename the file name
mv file_name ./folder_name --> to move the file into folder in same parent
folder (./ means in the same folder)
mv file_name ../folder_name --> to move the file into folder in folder one step
back(../ means in the earlier folder)
cp file_name1 file_name2 --> copy file
===================================================================================
==================================================
Chapter 01: Print Function
- in windows; >python file_name
- in mac/linux >python3 file_name to run the python program
String --> collection of characters inside the double quotes or single quotes
- can use double quotes or single quotes
> print("hello") or print('hello')
example:
i/p > print("hello 'hello' world")
o/p > hello 'hello' world
i/p > print('hello "hello" world')
o/p > hello "hello" world
i/p > print('hello 'hello' world')
o/p > syntax error ----> cannot use single quotes within single quotes;
same for double quotes
i/p > print('I'm Ajay')
o/p > syntax error ----> cannot use single quotes within single quotes
i/p > print("I'm Ajay")
o/p > I'm Ajay
===================================================================================
==================================================
Chapter 02: Escape Sequences
i/p > print("hello "hello" world")
o/p > syntax error
i/p > print("hello \"hello\" world") --> use of escape sequence characters
o/p > hello "hello" hello
example:
i/p> print("line A\nline B")
o/p> line A
line B
i/p> print("this is \ backslash")
o/p> this is \ backslash
i/p> print("this is backslash\")
o/p> SyntaxError: EOL while scanning string literal --> python interpretor is
considering \" as double quote
i/p> print("this is backslash\\")
o/p> this is backslash\
i/p> print("this is backslash\\\\")
o/p> this is backslash\\
i/p> print("hell\blo")
o/p> hello
i/p> print("hell\bxo")
o/p> helxo
===================================================================================
==================================================
Comments
#this is comment
print('hello') #this is for printing hello
-check for multiline comments????
===================================================================================
==================================================
Escape characters as normal text:
output: \" \'
print("\\\" \\\'")
===================================================================================
==================================================
Exercise:
Display the below lines as output:
This is \\ double backslash
These are /\/\/\/\ mountains
He is awesome
\" \n \t \'
Input:
print("This is \\\\ double backslash")
print("These are /\\/\\/\\/\\ mountains")
print("He is \t awesome")
print("\\\" \\n \\t \\\'")
===================================================================================
==================================================
Raw Strings -> can be used instead of escape characters
Input:
print("Line A \n Line B")
print(r"Line A \n Line B")
print("Line A \" Line B")
print(r"Line A \" Line B")
Output:
Line A
Line B
Line A \n Line B
Line A " Line B
Line A \" Line B
===================================================================================
==================================================
Print Emoji
https://unicode.org/emoji/charts/full-emoji-list.html
copy any code mentioned for emoji and paste as print("code_from_site")
print("U+1F600")
print("\U0001F600") --> replace + with 000 and add \ at start
===================================================================================
==================================================
Python as Calculator
Precedence Rule:
Parenthesis - Highest
Exponent - Right to Left
*, /, //, % - Left to Right
+, - - Left to Right
Input:
print(2+3*4)
print(4/2) # Floating point division
print(2/4) # Floating point division
print(4//2) # Integer division
print(2//4) # Integer division
print(2**3) # find 2*2*2
print(2**0.5) # find square root
print(round(2**0.5,3)) # round off upto given number
print(3%2)
print((3+2)/2)
print((2+3)*5/2%6)
print(2**3/2*6-4*(3-4/2))
Output:
14
2.0
0.5
2
0
8
1.4142135623730951
1.414
1
2.5
0.5
20.0
example for Exponent - Right to Left
print(2**3**2) --> here right to left means 2**9 i.e. first Right part (i.e3**2)
is calculated and then left part will be calculated.
512
print(2**9)
512
===================================================================================
==================================================
(2**3/2*6-4*(3-4/2)