0% found this document useful (0 votes)
20 views4 pages

Essential Python Basics Explained

The document covers basic topics of Python including variables and data types, operators, control flow, functions, data structures, and string manipulation. It provides examples for each topic, illustrating how to define variables, perform operations, control program flow, create reusable functions, store data in various structures, and manipulate strings. Each section includes sample code and expected output to demonstrate the concepts clearly.

Uploaded by

geevisajins52
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views4 pages

Essential Python Basics Explained

The document covers basic topics of Python including variables and data types, operators, control flow, functions, data structures, and string manipulation. It provides examples for each topic, illustrating how to define variables, perform operations, control program flow, create reusable functions, store data in various structures, and manipulate strings. Each section includes sample code and expected output to demonstrate the concepts clearly.

Uploaded by

geevisajins52
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Basic Topics of Python

1. Variables and Data Types

Variables are used to store data. Python has several basic data types:

- int: Whole numbers

- float: Numbers with decimals

- str: Text

- bool: True or False

Example:

x=5

y = 3.2

name = "Alice"

is_active = True

Output:

x is of type <class 'int'>

y is of type <class 'float'>

name is of type <class 'str'>

is_active is of type <class 'bool'>

2. Operators

Operators are used to perform operations on variables and values.

Example:

a = 10

b=3
print(a + b) # Addition

print(a > b) # Comparison

print(a == b or a > b) # Logical

Output:

13

True

True

3. Control Flow

Used to control the flow of a program using conditions and loops.

Example:

x=7

if x > 5:

print("Greater than 5")

else:

print("5 or less")

Output:

Greater than 5

4. Functions

Functions are blocks of reusable code.

Example:

def greet(name):

return "Hello " + name


print(greet("Bob"))

Output:

Hello Bob

5. Data Structures

Used to store collections of data.

Examples:

my_list = [1, 2, 3]

my_tuple = (1, 2, 3)

my_dict = {"a": 1, "b": 2}

my_set = {1, 2, 3}

Output:

List: [1, 2, 3]

Tuple: (1, 2, 3)

Dict: {'a': 1, 'b': 2}

Set: {1, 2, 3}

6. String Manipulation

Strings can be modified or accessed in parts.

Example:

text = "Hello"

print([Link]())

print(text[1:4])
Output:

HELLO

ell

You might also like