So what is Python?
If you want more in-depth information, check this link out:
Welcome to Python!
Below is a short intro to Python. For more details check out the links on this page!
Welcome to the Python Basics Guide! Whether you're a humanities major, a business student, or someone with no technical background, this guide is designed to help you understand the basics of Python programming. Python is a versatile and beginner-friendly programming language widely used in various fields. Let's dive in!
Python is a high-level, interpreted programming language known for its simplicity and readability. It is used for a variety of purposes, including web development, data analysis, artificial intelligence, automation, and more. Learning Python opens up a world of opportunities, even if you don't have a technical background.
Variables: Containers for storing data. When you declare a variable, you're essentially assigning a name to a value. For example:
name = "John"
age = 25
Here, name
is a variable storing the string "John," and age
is a variable storing the integer 25.
Data Types: Python has several built-in data types:
Strings (str
): Used for text. Enclose text in single ('
) or double ("
) quotes.
message = 'Hello, World!'
Integers (int
): Whole numbers without decimals.
count = 42
Floats (float
): Numbers with decimals.
pi = 3.14
Booleans (bool
): Represent either True
or False
.
is_student = True
Conditional Statements: Used to make decisions in your code based on conditions.
if condition:
# code to execute if condition is true
elif another_condition:
# code to execute if another_condition is true
else:
# code to execute if none of the conditions are true
For example:
age = 20
if age >= 18:
print("You are an adult.")
else:
print("You are a minor.")
Loops: Allow you to repeat a block of code.
for
Loop: Iterates over a sequence (like a list or string).
for item in iterable:
# Define a list of numbers
numbers = [1, 2, 3, 4, 5]
# Iterate over each element in the list using a for loop
for num in numbers:
# Print each number multiplied by 2
print(num * 2)
Example:
fruits = ["apple", "banana", "orange"]
for fruit in fruits:
print(fruit)
while
Loop: Repeats a block of code as long as a condition is true.
while condition:
# code to execute as long as the condition is true
Example:
count = 0
while count < 5:
print(count)
count += 1
Functions: Blocks of reusable code. You can define your own functions or use built-in ones.
def greet(name):
print("Hello, " + name + "!")
Example:
greet("Alice") # Output: Hello, Alice!
Functions can take parameters (like name
in the example) and return values. They help organize code and make it more modular.
Now that you know a bit more about Python, it's time to run Hello World! Head here: https://www.tutorialspoint.com/execute_python_online.php and click the '⚙️Execute' button in the top left hand corner. "Hello World" should print in the pane to the right. This is essentially the most basic program you can make and run.
Now that you know what a simple program looks like, here's some more information about what all that code is and what it does: https://www.w3schools.com/python/python_syntax.asp. Follow along with the tutorial and the exercises to familiarize yourself with what Python code looks like and how it works!
Feel free to go back over to https://www.tutorialspoint.com/execute_python_online.php to practice writing what you learned from the W3Schools tutorial