0% found this document useful (0 votes)
3 views2 pages

Python Basics Notes

This document provides a quick overview of Python basics, including data types such as integers, floats, strings, and collections like lists, tuples, dictionaries, and sets. It covers arithmetic operations, variable assignments, string manipulation, and print formatting. Additionally, it introduces boolean values and their usage in comparisons.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Python Basics Notes

This document provides a quick overview of Python basics, including data types such as integers, floats, strings, and collections like lists, tuples, dictionaries, and sets. It covers arithmetic operations, variable assignments, string manipulation, and print formatting. Additionally, it introduces boolean values and their usage in comparisons.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Basics - Quick Notes

Python Data Types


`int`: Whole numbers (e.g. `5`)

`float`: Decimal numbers (e.g. `3.14`)

`str`: Strings/text (e.g. "hello")

`bool`: Boolean values (`True`, `False`)

`list`, `tuple`, `dict`, `set`: Collection types

Python Numbers & Arithmetic


2+3 #5

5-2 #3

4*2 #8

10 / 2 # 5.0

5 ** 2 # 25

10 % 3 # 1 (remainder)

Variable Assignments
x = 10

name = "Alice"

pi = 3.14

Strings
my_string = "Hello, world!"

Indexing and Slicing:

my_string[0] # 'H'

my_string[-1] # '!'

my_string[0:5] # 'Hello'

String Methods:

my_string.upper() # 'HELLO, WORLD!'


my_string.lower() # 'hello, world!'

my_string.split(",") # ['Hello', ' world!']

Print Formatting:

name = "Alice"

age = 25

print(f"My name is {name} and I'm {age} years old.")

Lists
my_list = [1, 2, 3]

my_list.append(4)

print(my_list[0]) # 1

Dictionaries
my_dict = {"name": "Bob", "age": 30}

print(my_dict["name"]) # 'Bob'

Tuples
my_tuple = (1, 2, 3)

print(my_tuple[1]) # 2

Sets
my_set = {1, 2, 2, 3}

print(my_set) # {1, 2, 3}

Booleans
is_true = True

is_false = False

print(5 > 3) # True

print(3 == 4) # False

You might also like