Introduction to python
In [1]: print('Welcome to Velocity')
Welcome to Velocity
In [7]: print('Welcome to Velocity')
print('hello world')
Welcome to Velocity
hello world
In [6]: print('Welcome to Velocity')
Welcome to Velocity
In [4]: import time
for i in range(5):
time.sleep(2)
print(i)
0
1
2
3
4
In [5]: print('hello world')
hello world
In [8]: print('Welcome to python and data analytics')
print('Welcome to Velocity')
print('Hello world')
Welcome to python and data analytics
Welcome to Velocity
Hello world
In [10]: print('Welcome to python and data analytics')
time.sleep(2)
print('Welcome to Velocity')
time.sleep(2)
print('Hello world')
Welcome to python and data analytics
Welcome to Velocity
Hello world
Heading 1
esc + 1 # Markdown text
Heading 2
esc + 2 # Raw Text
Heading 3
In [14]: # esc + 3 # comment
heading 5
esc + 5
How to Run Cells in jupyter lab
In [ ]: 1. Control + enter ===> Used to run current cell/selected cell
2. Shift + enter ===> Used to run current cell and select a new cell if it exists,
3. Alt + enter ===> Used to run current cell and add new blank cell
In [15]: print('Hello world')
Hello world
In [16]: print('Python and data analytics')
Python and data analytics
In [20]: print('Python and data analytics')
Python and data analytics
In [18]: print('Python and data analytics')
Python and data analytics
In [ ]:
Featuers of Python
In [ ]: 1. Easy to code and easy to read
2. Simple syntax
3. High level programming language
4. Dynamically typed language
No need to declare datatype of any variable
type function is used for to check datatype of any variable
5. Robust and standard libraries/ packages/ Modules
import pandas # library
import numpy # library
import os # Module
!pip install library_name
6. Interpreted language
line by line
compile + run
In [21]: 10 + 20
Out [21]: 30
In [22]: a=10 # a is variable and 20 its value
b=20
add=a+b
print(add)
30
In [23]: id(a)
Out [23]: 140734644300504
In [24]: id(b) # id is used to find address of variable
Out [24]: 140734644300824
In [25]: type(a) # type is used for to check datatype of variable
Out [25]: int
In [26]: 10*20
Out [26]: 200
In [28]: for i in range(1,6):
print(i)
1
2
3
4
5
In [29]: for i in range(1,6): # indentation ==> a four white spaces bigining of the code
print(i)
Cell In[29], line 2
print(i)
^
IndentationError: expected an indented block after 'for' statement on line 1
In [30]: for i in range(1,6): # indentation ==> a four white spaces bigining of the code
print(i)
1
2
3
4
5
In [32]: for i in range(1,6): # indentation ==> a four white spaces bigining of the code
print('1. hello world')
print('2. hello world')
File <string>:3
print('2. hello world')
^
IndentationError: unindent does not match any outer indentation level
In [33]: for i in range(1,6): # indentation ==> a four white spaces bigining of the code
print('1. hello world')
print('2. hello world')
1. hello world
2. hello world
1. hello world
2. hello world
1. hello world
2. hello world
1. hello world
2. hello world
1. hello world
2. hello world
In [34]: for i in range(1,6): # indentation ==> a four white spaces bigining of the code
print('1. hello world')
print('2. hello world')
Cell In[34], line 3
print('2. hello world')
^
IndentationError: unexpected indent
In [35]: lst=[1,2,3,4,5]
odd_num=[]
for i in lst:
if i%2==1:
odd_num.append(i)
In [36]: odd_num
Out [36]: [1, 3, 5]
In [37]: a=10
a
Out [37]: 10
In [38]: b=10
b
Out [38]: 10
In [39]: id(a)
Out [39]: 140734644300504
In [40]: id(b)
Out [40]: 140734644300504
In [ ]: int x = 5;
int y = 6;
int sum = x + y;
System.out.println(sum); // Print the sum of x + y
In [41]: x=5
y=6
add=x+y
print(add)
11
In [42]: public class Main {
public static void main(String[] args) {
int x = 5;
int y = 6;
int sum = x + y;
System.out.println(sum); // Print the sum of x + y
}
}
Cell In[42], line 1
public class Main {
^
SyntaxError: invalid syntax
In [43]: a='10'
b='20'
add=a+b
print(add)
1020
In [45]: name='Gajanan'
last_name=' Sawadatkar'
name+last_name
Out [45]: 'Gajanan Sawadatkar'
In [46]: type(name)
Out [46]: str
In [47]: import numpy as np
import pandas as pd
data=np.random.randint(10,30,size=(5,4))
data
Out [47]: array([[12, 29, 16, 24],
[23, 11, 17, 26],
[15, 19, 19, 13],
[28, 10, 24, 17],
[13, 14, 11, 21]])
In [48]: df = pd.DataFrame(data,columns=list('ABCD'))
df
Out [48]:
A B C D
0 12 29 16 24
1 23 11 17 26
2 15 19 19 13
3 28 10 24 17
4 13 14 11 21
In [49]: print('Welcome to python and data analytics')
time.sleep(2)
print('Welcome to Velocity')
time.sleep(2)
print('Hello world')
Welcome to python and data analytics
Welcome to Velocity
Hello world
In [ ]: