Join this channel to learn data science, artificial intelligence and machine learning with funny quizzes, interesting projects and amazing resources for free
For collaborations: @love_data
Post #4089
4.1K
- ❤ 8
DA @datasciencefun
Showing posts older than #4091 · Back to latest
student = { "name": "Rahul", "age": 22, "course": "Data Science" }
print(student)
{'name': 'Rahul', 'age': 22, 'course': 'Data Science'}student = { "name": "Rahul", "age": 22 }
print(student["name"])
Rahulstudent = { "name": "Rahul", "age": 22 }
student["city"] = "Delhi"
print(student)
{'name': 'Rahul', 'age': 22, 'city': 'Delhi'}student["age"] = 23
student.pop("age")
print(student.get("name"))
Rahulprint(student.keys())
dict_keys(['name', 'age'])print(student.values())
dict_values(['Rahul', 22])print(student.items())
dict_items([('name', 'Rahul'), ('age', 22)])student = { "name": "Rahul", "age": 22 }
for key, value in student.items():
print(key, value)
if condition:
# code
age = 20
if age >= 18:
print("You can vote")
if condition:
# code if true
else:
# code if false
age = 16
if age >= 18:
print("Eligible to vote")
else:
print("Not eligible")
if condition1:
# code
elif condition2:
# code
else:
# code
marks = 75
if marks >= 90:
print("Grade A")
elif marks >= 60:
print("Grade B")
else:
print("Grade C")
age = 20
citizen = True
if age >= 18:
if citizen:
print("Eligible to vote")
age = 20
print("Adult") if age >= 18 else print("Minor")
def function_name():
# code
def greet():
print("Hello Deepak")
greet()
def greet(name):
print("Hello", name)
greet("Rahul")
def add(a, b):
return a + b
result = add(5, 3)
print(result)
def greet(name="Guest"):
print("Hello", name)
greet()
greet("Amit")
for variable in sequence:✅ Example — Print Numbers
# code
for i in range(5):Output: 0 1 2 3 4
print(i)
numbers = [10, 20, 30]👉 Used heavily in data science.
for num in numbers:
print(num)
while condition:✅ Example
# code
x = 1Output: 1 2 3 4 5
while x <= 5:
print(x)
x += 1
for i in range(5):Output: 0 1 2
if i == 3:
break
print(i)
for i in range(5):Output: 0 1 2 4
if i == 3:
continue
print(i)