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

Python Basics: Variables to OOP

The document provides an overview of basic programming concepts including variables, data types, input/output, conditional statements, loops, object-oriented programming (OOP), and inheritance. Each section includes syntax, example code, and expected output. It serves as a foundational guide for understanding these programming principles.

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)
5 views4 pages

Python Basics: Variables to OOP

The document provides an overview of basic programming concepts including variables, data types, input/output, conditional statements, loops, object-oriented programming (OOP), and inheritance. Each section includes syntax, example code, and expected output. It serves as a foundational guide for understanding these programming principles.

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

1.

Variables and Data Types

Syntax:

variable_name = value

Example Code:

a = 10

b = 5.5

name = "John"

is_valid = True

print(a, b, name, is_valid)

Output: 10 5.5 John True

2. Input and Output

Syntax:

input_var = input("Prompt message")

print(data)

Example Code:

name = input("Enter your name: ")

print("Hello", name)

Input: John

Output: Hello John

3. Conditional Statements

Syntax:

if condition:

statement

elif another_condition:

statement
else:

statement

Example Code:

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

if num > 0:

print("Positive")

elif num == 0:

print("Zero")

else:

print("Negative")

Input: 5

Output: Positive

4. Loops

Syntax:

# For loop

for var in iterable:

statement

# While loop

while condition:

statement

Example Code:

for i in range(1, 6):

print(i)

i=1
while i <= 5:

print(i)

i += 1

Output: 1 2 3 4 5 1 2 3 4 5

5. Object-Oriented Programming (OOP)

Syntax:

class ClassName:

def __init__(self, parameters):

[Link] = value

def method(self):

pass

object = ClassName(args)

Example Code:

class Person:

def __init__(self, name, age):

[Link] = name

[Link] = age

def greet(self):

print("Hello, my name is", [Link])

p = Person("Alice", 25)

[Link]()

Output: Hello, my name is Alice


6. Inheritance in OOP

Syntax:

class Parent:

def method(self):

pass

class Child(Parent):

def child_method(self):

pass

Example Code:

class Animal:

def sound(self):

print("Animal Sound")

class Dog(Animal):

def sound(self):

print("Bark")

d = Dog()

[Link]()

Output: Bark

You might also like