-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
Python is a popular, high-level programming language known for its simplicity and readability, making it great for beginners and experts alike. Developed in the late 1980s by Guido van Rossum, Python emphasizes code readability and allows developers to use fewer lines of code compared to other programming languages. Here are some core features and examples: | ||
|
||
1. **Interpreted Language**: Python code is executed line by line, making it easier to debug and test. You don’t need to compile Python code; it runs directly with the help of the Python interpreter. | ||
|
||
2. **Dynamically Typed**: Variables in Python don’t require explicit declaration of their type. Python automatically determines the type based on the value you assign. | ||
|
||
3. **Versatile Usage**: Python is used in web development, data analysis, machine learning, AI, automation, and more. | ||
|
||
4. **Large Community and Libraries**: Python has an extensive library ecosystem that provides tools for almost any application. Examples include NumPy for scientific computing, Django for web development, and TensorFlow for machine learning. | ||
|
||
5. **Easy Syntax**: Python's syntax is simple and closely resembles English, making it accessible for beginners. | ||
|
||
### Examples of Python Code | ||
|
||
#### Basic Syntax: Hello World | ||
This is a simple example that prints "Hello, World!" to the screen. | ||
|
||
```python | ||
print("Hello, World!") | ||
``` | ||
|
||
#### Variables and Data Types | ||
Python lets you create variables without declaring their type. | ||
|
||
```python | ||
name = "Alice" # String | ||
age = 25 # Integer | ||
height = 5.7 # Float | ||
is_student = True # Boolean | ||
|
||
print(f"Name: {name}, Age: {age}, Height: {height}, Student: {is_student}") | ||
``` | ||
|
||
#### Control Structures: Conditionals and Loops | ||
Python uses indentation to define blocks of code, unlike braces `{}` in other languages. | ||
|
||
```python | ||
# If-else statement | ||
if age >= 18: | ||
print("Adult") | ||
else: | ||
print("Minor") | ||
|
||
# For loop | ||
for i in range(5): | ||
print(i) | ||
|
||
# While loop | ||
count = 0 | ||
while count < 5: | ||
print(count) | ||
count += 1 | ||
``` | ||
|
||
#### Functions | ||
Functions allow you to organize code into reusable blocks. | ||
|
||
```python | ||
def greet(name): | ||
return f"Hello, {name}!" | ||
|
||
print(greet("Alice")) | ||
``` | ||
|
||
#### Lists and Dictionaries | ||
Python has built-in data structures like lists and dictionaries for handling collections of data. | ||
|
||
```python | ||
# List | ||
fruits = ["apple", "banana", "cherry"] | ||
for fruit in fruits: | ||
print(fruit) | ||
|
||
# Dictionary | ||
person = { | ||
"name": "Alice", | ||
"age": 25, | ||
"city": "Paris" | ||
} | ||
print(person["name"]) | ||
``` | ||
|
||
#### Classes and Objects (Object-Oriented Programming) | ||
Python supports object-oriented programming, making it easy to create classes and objects. | ||
|
||
```python | ||
class Dog: | ||
def __init__(self, name, age): | ||
self.name = name | ||
self.age = age | ||
|
||
def bark(self): | ||
return "Woof!" | ||
|
||
my_dog = Dog("Buddy", 3) | ||
print(my_dog.name) # Buddy | ||
print(my_dog.bark()) # Woof! | ||
``` | ||
|
||
Python’s simplicity, combined with its extensive libraries and versatility, makes it a powerful tool for a wide range of applications. |