Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Basics for python beginners

Rating
-
Sold
-
Pages
40
Uploaded on
28-02-2025
Written in
2024/2025

In this document you will be able to explore some basics of python as a beginner

Institution
Course

Content preview

, Chapter 1
Alright, let's start your Python journey! We'll cover the basics with clear explanations
and examples.

Lesson 1: Introduction to Python - Getting Started
1. What is Python?

 Python is a versatile and easy-to-learn programming language.

 It's used for various purposes, including web development, data analysis, and
automation.

 Its clear syntax makes it beginner-friendly.

2. Setting up Python:

 You'll need to install Python on your computer.

o Go to python.org and download the latest version.

o During installation, make sure to check the box that says "Add Python to PATH." This
will make it easier to run Python from your command line.

 You'll also need a text editor or an Integrated Development Environment (IDE).

o IDEs like VS Code, PyCharm, or Thonny are great for beginners. They provide features
like code highlighting and debugging.

3. Your First Python Program: "Hello, World!"

 Open your text editor or IDE.

 Type the following code:
Python
print("Hello, World!")

 Save the file as hello.py.

 Open your command prompt or terminal.

 Navigate to the directory where you saved the file.

, Run the program by typing: python hello.py

 You should see "Hello, World!" printed on the screen.

Explanation:
 print() is a built-in Python function that displays output on the console.

 "Hello, World!" is a string, which is a sequence of characters enclosed in quotation

marks.
4. Variables:

 Variables are used to store data.

 You can assign values to variables using the = operator.
Python
name = "Alice"
age = 30
print(name)
print(age)

Explanation:
 name and age are variables.

 "Alice" is a string value assigned to name.

 30 is an integer value assigned to age.

5. Data Types:

 Python has several built-in data types:

o Integers (int): Whole numbers (e.g., 10, -5).
o Floats (float): Decimal numbers (e.g., 3.14, 2.5).
o Strings (str): Text (e.g., "Hello").
o Booleans (bool): True or False.
Python
number = 10
decimal = 3.14
text = "Python"
is_true = True


print(type(number)) #output <class 'int'>
print(type(decimal)) #output <class 'float'>

, print(type(text)) #output <class 'str'>
print(type(is_true)) #output <class 'bool'>

Explanation:
 The type() function returns the data type of a variable.
6. Basic Operators:

 Python supports various operators for performing calculations and comparisons:

o Arithmetic Operators: + (addition), - (subtraction), * (multiplication), / (division), // (floor
division), % (modulo).
o Comparison Operators: == (equal to), != (not equal to), > (greater than), < (less than),
>= (greater than or equal to), <= (less than or equal to). 1




Python
x = 10
y = 5


print(x + y) # Output: 15
print(x - y) # Output: 5
print(x * y) # Output: 50
print(x / y) # Output: 2.0
print(x == y) # Output: False
print(x > y) # Output: True

7. Input:
 The input() function allows you to get input from the user.
Python
user_name = input("Enter your name: ")
print("Hello, " + user_name + "!")

Explanation:
 The input() function displays a prompt and waits for the user to enter input.
 The input is stored as a string in the user_name variable.
Practice Exercises:

1. Write a program that asks the user for their age and prints it.

2. Write a program that calculates the area of a rectangle (length * width).

3. Write a program that asks for two numbers and prints the sum, difference, product, and
quotient.

Written for

Course

Document information

Uploaded on
February 28, 2025
Number of pages
40
Written in
2024/2025
Type
Class notes
Professor(s)
None
Contains
All classes

Subjects

$7.19
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
khasangogenesisdavid

Get to know the seller

Seller avatar
khasangogenesisdavid Self
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
1
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions