Sei sulla pagina 1di 1

PYTHON FOR DATA List Operations

Operations Flow Control Method Generic Operations

SCIENCE
• if-else (Conditional Statement) • range(5): 0,1,2,3,4
• List=[]: Defines an empty list
• list[i]=a: Stores a at the ith position
if price>=700: • S=input(“Enter:”)

CHEAT SHEET
print(“Buy.”)
• list[i]: Retrieves the character at the ith position else: • Len(a): Gives item count in a
print(“Don’t buy.”)
• list[i:j]: Retrieves characters in the range i to j • For loop (Iterative Loop Statement) • min(a): Gives minimum value in a

Python Basics • list.append(val): Adds item at the end a=“New Text”


• max(a): Gives minimum value in a
count=0
• list.pop([i]): Removes and returns item at index i for i in a: • sum(a): Adds up items of an iterable and returns
if i==‘e’:
String Operations count=count+1 sum
Datatypes • String[i]: Retrieves the character at the ith position print(count)
• sorted(a): Sorted list copy of a
• While loop (Conditional Loop Statement)
• String[i:j]: Retrieves characters in the range i to j
a=0 • importing modules: import random
• Numbers: a=2(Integer), • String: a=“New String” Dictionary Operations i=1
while i <10:
b=2.0(Float), c=1+2j(Complex)
• Sets: a= {2,3,4,5} • dict={} : Defines an empty dictionary a=a*2
• List: a=[1,2,3,’Word’] i=i+1
File Operations
• dict[i]=a: stores “a” to the key “i”
• Dictionary: x= {‘a’: print(a)
• Tuple: a= (1,2,4) • dict[i]: Retrieves the item with the key “i” • Loop Control: Break, Pass and continue f= open(“File Name”,“opening mode”)
[1,2],‘b’: [4,6]}
• dict.key: Gives all the key items
(Opening modes: r: read, w: write, a: append, r+: both read
• dict.values: Gives all the values Functions
Operators and write)

def new_function():
Numeric Operator: (Say, a holds 5, b holds 10) OOPS print("Hello World") Try & Except Block
• a + b = 15 • b/a = 2 Inheritance: try:
• a – b = -5 new_function()
• b%a=0 A process of using details from a new class without
• a * b = 50 modifying existing class. [Statement body block]
• a**b =9765625
• 7.0//2.0 = 3.0, -11//3 = -4 Polymorphism: Lambda Function raise Exception()

Comparison Operator: A concept of using common operation in different ways for except Exception as e:
different data input. lambda a,b: a+b
• (a == b): not true • (a > b): not true [Error processing block]
Encapsulation:
• (a!= b): true • (a >= b): not true lambda a,b: a*b
Hiding the private details of a class from other objects.
• (a > b): not true • (a <= b) is true
Boolean Operator: Comments
Class/object
• a and b
Class: class Pen: # Single Line Comment
• a or b
pass """
• not a
Multi-line comment
Object: obj=Pen() FURTHERMORE:
"""
Python for Data Science Certification Training Course

Potrebbero piacerti anche