Vous êtes sur la page 1sur 11

Java WorkShop

int number1;
int number2;
{
System.out.println((double)number1/number2);
}
{number1 is converted to a double 13.0/4}
{number2 is converted to a double13.0/4.0}

PROGRAM 1
public returnValueType methodName();
public static int count; -> class field
public int count; -> instance field
class SubclassName extends SuperClass Name{
}

Python Workshop
 Number
 String
 List
 Tuple
 Dict.

GROUPING
>>> name,email,age="Ashish","mehra1238@gmail.com",19
>>> age
19
>>> email
'mehra1238@gmail.com'
>>> name
'Ashish'
>>> Ashish=Abhishek="CU"
>>> Abhishek
'CU'
>>>

LIST
>>> student=["ashish","abhishek","naman","riyansh"]
>>> student
['ashish', 'abhishek', 'naman', 'riyansh']
>>> student[0]
'ashish'
>>> student[0][]3
File "<stdin>", line 1
student[0][]3
>>> student[0][3]
'i'
>>> student[4]
>>> student[3][1][2][3]
>>>
>>> student[3][3]
'a'
>>> student[-3]
'abhishek'
>>> student.reverse()
>>> student
['riyansh', 'naman', 'abhishek', 'ashish']
>>> student.sort()
>>> student
['abhishek', 'ashish', 'naman', 'riyansh']
>>>

SORTING
>>> a=[1,4,2,7,5,3]
>>> a.sort()
>>> a
[1, 2, 3, 4, 5, 7]
>>> a.sort(reverse=True)
>>> a
[7, 5, 4, 3, 2, 1]
>>>

APPEND or ADD
>>> s=["ashish","aashu","abhi","naman"]
>>> s.sort
<built-in method sort of list object at 0x000002471AD76288>
>>> s.sort()
>>> s
['aashu', 'abhi', 'ashish', 'naman']
>>> s.append(20)
>>> s
['aashu', 'abhi', 'ashish', 'naman', 20]
>>> s.append([30,"google"])
>>> s
['aashu', 'abhi', 'ashish', 'naman', 20, [30, 'google']]
>>> s[5]
[30, 'google']
>>> s[5][1]
'google'
>>>

MIN, MAX, POP or REMOVE


>>> s1=[4,34,42,67,58]
>>> ss=s+s1
>>> ss
['aashu', 'abhi', 'ashish', 'naman', 20, [30, 'google'], 4, 34, 42, 67, 58]
>>> max(s1)
67
>>> min(s1)
4
>>> s.pop(20)
>>> s.pop(2)
'ashish'
>>> s
['aashu', 'abhi', 'naman', 20, [30, 'google']]
>>>s1.count(45)
2
>>>s1.remove(23)
>>>s1
[43,45,12,67]
>>>s

SLICING
>>> s=["ashish","rohan","rahul","aashu","ravi"]
>>> s
['ashish', 'rohan', 'rahul', 'aashu', 'ravi']
>>> s[:]
['ashish', 'rohan', 'rahul', 'aashu', 'ravi']
>>> s[2]="gopal"
>>> s[:]
['ashish', 'rohan', 'gopal', 'aashu', 'ravi']
>>> s[1:]
['rohan', 'gopal', 'aashu', 'ravi']
>>> s[1:2]
['rohan']
>>>

TUPLE
>>> x=(12,4,56,76,98)
>>> type(x)
<class 'tuple'>
>>> x[0]=13
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>> x[0]
12
>>> x.remove(56)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Attribute Error: 'tuple' object has no attribute 'remove'
>>> y=(12,5,98,44)
>>> x+y
(12, 4, 56, 76, 98, 12, 5, 98, 44)
>>> z=x+y
>>> z
(12, 4, 56, 76, 98, 12, 5, 98, 44)
>>> z.sort()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'tuple' object has no attribute 'sort'
>>> x+y.(srort)
File "<stdin>", line 1
x+y.(srort)
^
SyntaxError: invalid syntax
>>> x.count(4)
1
>>> x.index(12)
0
>>> x.count(12)
1
>>> z.count(12)
2
>>> z.index()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: index() takes at least 1 argument (0 given)
>>> list(x)
[12, 4, 56, 76, 98]
>>>
>>> y=list
>>>
>>> y
<class 'list'>
>>> y=list(x)
>>> y
[12, 4, 56, 76, 98]
>>> type(y)
<class 'list'>
>>> tuple(y)
(12, 4, 56, 76, 98)
>>> x*2
(12, 4, 56, 76, 98, 12, 4, 56, 76, 98)
>>> y*2
[12, 4, 56, 76, 98, 12, 4, 56, 76, 98]
>>> name="vipul"
>>> name*2
'vipulvipul'
>>>

DICTIONARY :- It is represented by {}, key-value pair

>>> s={"name":"Ashish", "Age":19}


>>> s
{'name': 'Ashish', 'Age': 19}
>>> s.keys()
dict_keys(['name', 'Age'])
>>> s.values()
dict_values(['Ashish', 19])
>>>s[“Name”]
‘Ashish’
>>>s["Age"]
19
>>> len(s) */ for length of the dict.
2
>>> del s["Age"]
>>> s
{'name': 'Ashish'}
>>> s.clear()
>>> s
{}
>>> del s
>>> s
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 's' is not defined
>>> s={(1,2):"vipul"}
>>> s.keys()
dict_keys([(1, 2)])
>>> s1={"age":34}
>>> s.update(s1)
>>> s
{(1, 2): 'vipul', 'age': 34}
>>>
Programs

#Condition Checking
#If_Else
username,passs1=input("Enter username and password").split(",")
user_name="Ashish"
password="12345"
if(username==user_name and passs1==password):
print("Welcome")
else:
print("Sorry wrong password")

#Condition Checking
#If_Else
username,passs1=input("Enter username and password").split(",")
user_name="Ashish"
password="12345"
if(username==user_name and passs1==password):
print("Welcome")
elif(username=="Abhishek" and passs1==password):
print("Welcome abhishek")
else:
print("Sorry wrong password")

#looping
#for loop
for i in range(0,10):
print(i)

Exception Handling

Packages….
1.) Numpy --->
2.) Pandas ---> File Handling
3.) Matplotlib/Seaborn ---> Plotting or Visualisation

Vous aimerez peut-être aussi