0% found this document useful (0 votes)
4 views3 pages

Python Topics With Examples

The document provides an overview of basic programming concepts including variables, data types, input/output, operators, conditional statements, loops, lists, tuples, dictionaries, sets, and functions. Each section includes code examples and their corresponding outputs to illustrate the concepts. It serves as a foundational guide for understanding Python programming syntax and functionality.

Uploaded by

kiffaytullashaik
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)
4 views3 pages

Python Topics With Examples

The document provides an overview of basic programming concepts including variables, data types, input/output, operators, conditional statements, loops, lists, tuples, dictionaries, sets, and functions. Each section includes code examples and their corresponding outputs to illustrate the concepts. It serves as a foundational guide for understanding Python programming syntax and functionality.

Uploaded by

kiffaytullashaik
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
You are on page 1/ 3

1.

Variables and Data Types

Code:

a = 10 # Integer

b = 5.5 # Float

name = "John" # String

is_valid = True # Boolean

print(a, b, name, is_valid)

Output: 10 5.5 John True

2. Input and Output

Code:

name = input("Enter your name: ")

print("Hello", name)

Input: John

Output: Hello John

3. Operators

Code:

x = 10

y=3

print(x + y, x - y, x * y, x / y, x % y, x ** y)

Output: 13 7 30 3.3333333333333335 1 1000

4. Conditional Statements

Code:

num = int(input("Enter number: "))

if num > 0:
print("Positive")

elif num == 0:

print("Zero")

else:

print("Negative")

Input: 5

Output: Positive

5. Loops (While and For)

Code:

# While loop

i=1

while i <= 5:

print(i)

i += 1

# For loop

for i in range(1, 6):

print(i)

Output: 1 2 3 4 5 (Repeated)

6. Lists

Code:

fruits = ["apple", "banana", "cherry"]

fruits.append("orange")

print(fruits)

Output: ['apple', 'banana', 'cherry', 'orange']


7. Tuples

Code:

t = (1, 2, 3)

print(t[0])

Output: 1

8. Dictionaries

Code:

student = {"name": "Alice", "age": 20}

print(student["name"])

Output: Alice

9. Sets

Code:

s = {1, 2, 3, 3}

s.add(4)

print(s)

Output: {1, 2, 3, 4}

10. Functions

Code:

def add(x, y):

return x + y

print(add(5, 3))

Output: 8

You might also like