You are on page 1of 4

Python class 1:

Common command lines for windows user:

Open the command prompt on desktop then the following command lines can be used for different uses
like

cd,it is to know the current directory

dis for to list folders in the current directory

cd<space> foldername is used to jump to that folder in the current directory

cd<space>.. is used to jump back or go back

cls is used to clear the screen

Jupyter notebook is an open source interface used to write python code{here}

In the jupyter notebook click on cell-- run cell : to run the code

And shift+enter gives you a new cell/ runs the current cell code and gives new cell

PYTHON DATATYPES:

Type example
name
integer Int 2 300 40
Floating point float 25.4 200.0
Strings str Ordered sequence of characters: “hello”
‘hello’ “2000” ‘2000’ etc
Lists List Ordered sequence of objects:
[10,”hello”,200.3]
Dictionaries Dict Unordered key:value pairs:
{“mykey”:”value”,”name”:”frankie”}
Tuples Tup Ordered immutable sequence of objects:
(10,”hello”,200.4)
Sets Set Unordered collection of unique objects:
{“q”,”b”}
Boolean bool logical value indicating True or False

Operation codes:

Addition: 2+1
Subtraction:2-1

Multiplication: 2*3

Division:2/3

3//2 – it gives only the quotient value or u can say it doesnot round up the value of3/2 i.e 1.5 and gives
the final value as only 1

3%2 -it gives the remainder

2**3- it implies power i.e 2^3

When brackets are not given to the code where more than one arithemetic operation takes place it
follows BODMAS

Variable assignments:

Rules: no spaces between variable name, can use underscore instead

Shouldnot start with number,can not use any other special characters

Generally prefer lowercase to name variables-best practice

Should not use keywords like list str

Python uses dynamic typing I.e a variable can be assigned to different data types in a code

Eg: my_dog=1

my_dog=“Sammy”

this is allowed in python but not in other languages where it leads to error

eg:

code:

a=3 //value assigned//

<when run the code the o/p will be 3>

Code2:

a=5

a=a+a // this line implies the previous value of a is added up twice and assigned the new value to a//

<when code is run output will be 10>


In jupyter notebook as the code is written in cells whenever the same cell is run (here,a=a+a) it keeps on
increasing like from 10,20,40 and so on but not possible on other environments

We can even the data type of the variable by typing

type(a)

String: sequence of characters either in double quotes or single quotes,

Indexing: grabbing a single character from sequence of characters

Eg:

Character: h e l l o

Index: 01234

Reverse index: 0 -4 -3 -2 -1

Every character has a index, generally start with 0. Spacing doesnot counts

Indexing action use [] and a number index to indicate positions of what you wish to grab.

Slicing: it allows you to grab subsection of multiple characters

The syntax of slicing is: [start:stop:step]

Start – numerical index for the slice start

Stop- is the index you will go upto(but not include)

Step- is the size of the jump you take

Example in the notebook

Note: when a string is given print command the output doesnot show the double quotes or single
quotes but when executing the code u don’t give print command but just run a string code the output
will be seen in the quotes given, u can see the example the jupyter notebook and the other scenarios
are also seen in it

\n -new line

\t- more space


len(‘string’)- gives length of the string

string properties:

 Immutability: u cannot change a string, like if a string is given name=sam and now u want to
change it to pam by giving name[0]=’p’ this gives error. Rather we can change it by merging two
strings. Remember u cannot add number to string. See the example in notebook.

00123654789p0ol.,m bx

You might also like