- Print Statements:Printing text to the console is often the first thing you learn in any programming language. In Python, you can use the
print()
function:pythonCopy codeprint("Hello, World!")
- Variables:Variables are used to store data. Python is dynamically typed, so you don’t need to declare the data type explicitly.pythonCopy code
name = "John" age = 30
- Data Types:Python supports various data types, including integers, floats, strings, booleans, and more.pythonCopy code
num = 42 pi = 3.14 text = "Python" is_student = True
- Lists:Lists are used to store a collection of items.pythonCopy code
fruits = ["apple", "banana", "cherry"]
- Loops:You can use loops to perform repetitive tasks.pythonCopy code
for fruit in fruits: print(fruit)
- Conditional Statements:Conditional statements like
if
,elif
, andelse
allow you to make decisions in your code.pythonCopy codeage = 18 if age < 18: print("You are a minor.") elif age == 18: print("You are just 18!") else: print("You are an adult.")
- Functions:Functions allow you to encapsulate code into reusable blocks.pythonCopy code
def greet(name): print("Hello, " + name + "!") greet("Alice")
- Comments:Comments are used to add explanations to your code.pythonCopy code
# This is a comment
- User Input:You can get input from the user using the
input()
function.pythonCopy codename = input("What's your name? ")
- Indentation:Python uses indentation (whitespace) to define code blocks, unlike languages that use braces or keywords.
pythonCopy codeif condition:
# This is inside the if block
print("It's true!")
# This is outside the if block
These are some of the very basics of Python. As you continue learning, you’ll explore more advanced topics like classes, modules, file I/O, and libraries for specific tasks. Python has a rich ecosystem and is a great language for beginners and experienced programmers alike.