Python is a versatile and beginner-friendly programming language widely used in data science, web development, and automation. Here's a quick overview of some fundamental concepts:
1. Variables:
* Variables are used to store data values. They are assigned using the
= operator. Example: x = 10, name = "Alice"2. Data Types:
* Python has several built-in data types:
* Integer (int): Whole numbers (e.g.,
1, -5).* Float (float): Decimal numbers (e.g.,
3.14, -2.5).* String (str): Textual data (e.g.,
"Hello", 'Python').* Boolean (bool):
True or False values.* List: Ordered collection of items (e.g.,
[1, 2, "apple"]).* Tuple: Ordered, immutable collection (e.g.,
(1, 2, "apple")).* Dictionary: Key-value pairs (e.g.,
{"name": "Alice", "age": 30}).3. Operators:
* Python supports various operators for performing operations:
* Arithmetic Operators:
+, -, *, /, // (floor division), % (modulus), * (exponentiation).* Comparison Operators:
==, !=, >, <, >=, <=.* Logical Operators:
and, or, not.* Assignment Operators:
=, +=, -=, *=, /=, etc.4. Control Flow:
* Control flow statements determine the order in which code is executed:
*
if, elif, else: Conditional execution.*
for loop: Iterating over a sequence (list, string, etc.).*
while loop: Repeating a block of code as long as a condition is true.5. Functions:
* Functions are reusable blocks of code defined using the
def keyword.def greet(name):
print("Hello, " + name + "!")
greet("Bob") # Output: Hello, Bob!
6. Lists:
* Lists are ordered, mutable (changeable) collections.
* Create:
my_list = [1, 2, 3, "a"]* Access:
my_list[0] (first element)* Modify:
my_list.append(4), my_list.remove(2)7. Dictionaries:
* Dictionaries store key-value pairs.
* Create:
my_dict = {"name": "Alice", "age": 30}* Access:
my_dict["name"] (gets "Alice")* Modify:
my_dict["city"] = "New York"8. Loops:
* For Loops:
my_list = [1, 2, 3]
for item in my_list:
print(item)
* While Loops:
count = 0
while count < 5:
print(count)
count += 1
9. String Manipulation:
* Slicing:
my_string[1:4] (extracts a portion of the string)* Concatenation:
"Hello" + " " + "World"* Useful Methods:
.upper(), .lower(), .strip(), .replace(), .split()10. Modules and Libraries:
*
import statement is used to include code from external modules (libraries).* Example:
import math
print(math.sqrt(16)) # Output: 4.0
Python Programming Resources: https://whatsapp.com/channel/0029VaiM08SDuMRaGKd9Wv0L
Hope it helps :)