



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




age = 25 name = "Alice"
Data Types
print(type(age)) _# Output: _ print(type(name)) _# Output: _ Operators
# Arithmetic operators sum = 10 + 5 # Addition product = 10 * 5 _# Multiplication
is_equal = (age == 25 ) _# Checks if age is equal to 25
is_valid = (age > 18 ) and (name == "Alice") # Returns True if both conditions are met Expressions
total_price = price * quantity # Here, total_price is an expression
Functions
def greet(name): return f"Hello, {name}!" message = greet("Alice") print(message) # Output: Hello, Alice!
Working with Data and Libraries
Lists
fruits = ["apple", "banana", "cherry"] fruits.append("orange") # Adding an item print(fruits) # Output: ['apple', 'banana', 'cherry', 'orange']
Dictionaries
person = { "name": "Alice", "age": 30 , "city": "New York" } print(person["name"]) # Output: Alice
Sets
numbers = { 1 , 2 , 2 , 3 , 4 } print(numbers) # Output: {1, 2, 3, 4}
Tuples
coordinates = (10.0, 20.0) print(coordinates[ 0 ]) # Output: 10. Libraries for Data Manipulation
import numpy as np array = np.array([ 1 , 2 , 3 , 4 , 5 ]) print(array.mean()) # Output: 3.
import pandas as pd data = {'Name': ['Alice', 'Bob'], 'Age': [ 30 , 25 ]} df = pd.DataFrame(data) print(df)
Intermediate Python Topics and Summary