Skip to content

Muhammadm456/Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

name = "maaz" age = 27 price = 50 age2 =age

print(name) print(age2) print(price)

print(type(name)) print(type(age)) print(type(price))

a = 2 b = 9 diff = a - b print(diff)

my_dict = {"name": "Bob", "age": 25} print(my_dict["name"]) # Access value by key my_dict["age"] = 26 # Update value

n = 5 if n > 2: print("Greater than 2") elif n == 2: print("Equal to 2") else: print("Less than 2")

Loop through a range

for i in range(5): # range(5) generates 0, 1, 2, 3, 4 print(i)

Loop through a list

fruits = ["apple", "banana"] for fruit in fruits: print(fruit)

i = 0 while i < 5: print(i) i += 1

def greet(name="World"): # Default parameter value return f"Hello, {name}!"

message = greet("Python") print(message) # Output: Hello, Python!

class MyClass: # Constructor def init(self, nums): self.nums = nums self.size = len(nums)

# Method
def get_length(self):
    return self.size

Creating an object (instance)

my_obj = MyClass([1, 2, 3]) print(my_obj.get_length())

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published