1 Introduction to Python (1) Flashcards
Python basics , Numpy... Colab ipynb: https://colab.research.google.com/drive/18d3Tb0gSaOFfbUWL5yYlgYmaS9j-wOYs?usp=sharing
1 What is Python?
A general-purpose programming language
2 What is Data Science?
An interdisciplinary field that uses scientific methods, processes, algorithms and systems to extract knowledge and insights from data
3 Data Science as an intersection of three fields. Which ones?
- Computer Science IT
- Math and Statistics
- Domains/Business Knowledge
4 What is an algorithm ?
A finite sequence of computer-implementable instructions
5 What is a Python script?
A collection of commands in a file designed to be executed like a program
6 What is a Shell?
A software program that interprets commands from the user so that the operating system can understand them and perform the appropriate functions. The shell is a command-line interface, which means it is solely text-based
7 Outcome of:
print(10/2)
5
8 How to write exponentiation?
**
2**3=8
9 What does % Modulo?
Returns the remainder of a division
18 % 7 =5
10 What is a variable assignment
A name attached to a particular object
variable_a= 18
11 Create a variable ‘savings’ with value 100 and print it
savings = 100
print(savings)
12 Write a script to compound these variables:
savings =100
growth_multiplier = 1.1
t=1
result = savings*growth_multiplier**t
result
13 What is type conversion?
An object from one data type to another data type
14 Outcome of:
type(‘a’)
str
15 Outcome of:
type(False)
bool
16 Outcome of:
type(3)
int
17 Outcome of:
type(3.3)
float
18 Complete code:
’'’savings = 100
result =savings*1.10**7
print(…)
Outcome:
I started with $100 and now I have 194.9
savings = 100 savings = 100 result = round(savings * 1.10**7,1) print('I started with $' + str(savings) \+ ' and now I have $' +str(result))
19 What is a list?
A data structure in Python that is a mutable, or changeable, ordered sequence of elements. Each element or value that is inside of a list is called an item.
Lists are defined by having values between square brackets [ ]
20 Create a list called house with elements ‘room, kitchen’
#Outcome: ['room', 'kitchen']
house = [‘room’, ‘kitchen’]
house
21 Can a list contain different types of data such as a string and a float?
Yes
[1+2,’a’*5]
22 What is a list of lists or a multi-dimensional list?
A list inside a list (nested)
23 Use list a get this outcome:
[[‘a’,’b’],’c’]
m_list=[[‘a’,’b’],’c’]
m_list
24 What is subsetting?
The process of retrieving just the parts of large files
25 Get the output (2 ways)
x= [‘a’, ‘b’ , ‘c’, ‘d’]
x[1];x[-3]
26 What is an index in a list?
Refers to a position within an ordered list
27 Subset and operate
x= [‘a’, ‘b’ , ‘c’, ‘d’]
print(x[1]+x[2])
x[1]+x[2]
28 What is slicing?
Slicing in Python is a feature that enables accessing parts of sequences like strings, tuples, and lists
29 Slice
x= [‘a’, ‘b’ , ‘c’, ‘d’]
x[1:3]
30 Slice (2 ways)
x= [‘a’, ‘b’ , ‘c’, ‘d’]
print(x[1:3])
print(x[-3:-1])
31 Subsetting lists of lists
x=[[‘a’, ‘b’, ‘c’ ],
[‘d’,’e’, ‘f’]]
print(x[1][0])
32 Replace list elements
x = [‘a’, ‘b’, ‘c’,’d’]
x[2:]= [7,8]
x