Python:
Overview:
Python is a high-level, versatile, and widely-used programming language known for its simplicity and readability. It supports various programming paradigms, including procedural, object-oriented, and functional programming. Python is often used for web development, data analysis, scientific computing, artificial intelligence, and more.
Readability:
Python’s clean and easy-to-read syntax makes it an excellent choice for beginners and experienced programmers alike.
Interpreted:
Python is an interpreted language, which means that you can execute code directly, making it easy for experimentation and development.
Large Standard Library:
Python comes with a vast standard library that includes modules and packages for a wide range of tasks, reducing the need for external libraries.
Cross-Platform:
Python is available on various platforms and operating systems, making it highly portable.
Examples:
1
# Create a list of fruits
fruits = ["apple", "banana", "cherry"]
# Iterate over the list and display each fruit
for fruit in fruits:
print("I love " + fruit)
I love apple
I love banana
I love cherry
2
aList = []
while True:
USER_INPUT = input("Enter an item you want (or 'q' to quit): ")
if USER_INPUT == 'q':
break
aList.append(USER_INPUT)
print(aList)
['a']
3
A = True
B = True
if A and B:
print("It's true!")
It's true!
4
def applyDiscount(cost, percentDiscounted):
temp = 100 - percentDiscounted
temp = temp / 100
cost = cost * temp
return cost
price = applyDiscount(60, 20)
def applyTax(cost, percentTaxed):
temp = 100 + percentTaxed
temp = temp / 100
cost = cost * temp
return cost
price = applyTax(price, 8)
print("Final price after discount and tax:", price)
Final price after discount and tax: 51.84