forked from Generation-Data/24_int_data_eng_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_basic.py
More file actions
62 lines (50 loc) · 1.47 KB
/
python_basic.py
File metadata and controls
62 lines (50 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#python basics
# >>>Variables and Data Types
a = 500 # Integer
b = 3.14 # Float
c = "Hello, TEXAS TEXAS TEXAS!" # String
d = True # Boolean
print(d)
print(c)
# >>>Basic Operations
sum = a + b # Addition
difference = a - b # Subtraction
product = a * b # Multiplication
quotient = a / b # Division
print(product)
print(quotient)
# >>>Control Structures
if a > b:
print("a is greater than b")
else:
print("a is not greater than b")
# Loop
for i in range(5):
print(i)
# >>>Function Definition
#"Functions help us modularize our code. Here's how to define and call a function:"
def greet(name):
return f"Hello, {name}!"
# Function Call
print(greet("NEXT RUN"))
# #"Modules allow us to use code written by others. For instance, we can use the math module for advanced mathematical operations:"
import math
print(math.sqrt(25)) # Square root
# >>> Pandas and Numpy
#"For data analysis, some key libraries we'll use are pandas and numpy:"
import pandas as pd
import numpy as np
# Example with pandas
data = {'Name': ['John', 'Anna', 'Peter', 'Linda'],
'Age': [28, 24, 35, 32]}
df = pd.DataFrame(data)
print(df)
# >>>File Handling and Basic I/O
# "Lastly, handling files is an essential skill. Here's a simple example of reading from and writing to a file:"
# Writing to a file
with open('example.txt', 'w') as file:
file.write("Hello, this is a test file.\n")
# Reading from a file
with open('example.txt', 'r') as file:
content = file.read()
print(content)