0% found this document useful (0 votes)
3 views

Python - 1

Uploaded by

nwobodope
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python - 1

Uploaded by

nwobodope
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Introduction

to
PYTHON
ASSIGNING A VARIABLE
Assigning a variable in programming refers to the process
of associating a value with a symbolic name (the variable
name) so that the program can refer to and manipulate
that value using the given name. It is essentially storing a
piece of data in a memory location and giving it a label for
convenient reference.

To assign a variable, we need three components:

Variable name: We can decide what we would like to


Variables name our variable but keep in mind it can be short and
A variable is a named storage location descriptive. We will learn about certain naming
used to store data in a program. conventions we must follow in a bit.

It is a way to give a name to a memory Assignment operator: The variable name will be
location, making it easier to reference followed by the assignment operator. The assignment
and manipulate data. operator is an equal sign (=).

Variables are used in various The value: The value we assign to a variable can be
programming tasks, such as numerical or consist of characters, known as strings. In
calculations, storage, and manipulation this part of the lesson, we will only be focusing on using
of data. numerical values
DATA TYPES
Variables in Python hold values of different kinds. Data
types dictate what kind of data a variable can store and, in
some cases, the amount of memory allocated to it.

Understanding data types allows us to make assumptions


about the kind of operations that can be applied to a given
variable.

Python makes use of five primitive variable types:

• Integers
• Floats
• Strings
• Booleans

These data types can be categorized into 3 major groups

1. Numbers
2. Strings (Text)
3. Booleans
1. NUMBERS
This group categorizes all numerical data:

• INTEGERS:
Positive or negative whole numbers with no
fractional components.

Examples: 5, -10, 365.

• FLOAT DATA TYPE:


Represents real numbers with decimal points.

Examples: 3.142, -0.5, 9.8.


2. STRINGS (TEXT)
Strings in Python are sequences of characters
enclosed in quotes, either single (') or double
("). They are versatile and widely used for
representing textual data.

Strings can contain letters, numbers, symbols


and even spaces.

Examples: ”Hello, World!”


‘Python is easy!’
“Password123”
3. BOOLEAN
Booleans are built-in data types capable of
taking one of two possible values: True or
False (interchangeable with the integers 1
and 0).

Booleans control the flow of a program and are


used to make comparisons. Although they are
nicknamed bool in Python, they play an
integral role.

Boolean data types are mostly used with


comparison and logical operators.

Examples: >, <, =.


DATA STRUCTURES
Data structures help organize and store data
efficiently. They define how data is arranged,
accessed, and manipulated in a program.

Understanding data structures allows us to


choose the best way to store and retrieve
information based on specific use cases.

Python provides several built-in data structures,


including:

Lists – Ordered, mutable collections of items.


Tuples – Ordered, immutable collections of items.
Dictionaries – Key-value pairs for fast lookups.
Sets – Unordered collections of unique items.

Each data structure has its own properties,


advantages, and use cases in programming.
1. LISTS
Lists in Python are ordered collections of
items, enclosed in square brackets []. They
can store elements of different data types,
including numbers, strings, and even other
lists.

Lists are mutable, meaning their elements can


be changed, added, or removed.

Examples:

fruits = ["Apple", "Banana", "Cherry"]


numbers = [10, 20, 30, 40]
mixed = ["Python", 3.14, 42]
2. TUPLES
Tuples are ordered collections of items,
enclosed in parentheses (). Unlike lists, tuples
are immutable, meaning their elements
cannot be changed after creation.

Tuples are useful for storing fixed sets of


values that should not be modified.

Examples:

coordinates = (4.5, 9.8)


colors = ("Red", "Green", "Blue")
info = ("Alice", 25, "Developer")
3. DICTIONARIES
Dictionaries are unordered collections of key-
value pairs, enclosed in curly braces {}. They
allow efficient data retrieval by using keys
instead of index positions.

Dictionaries are mutable, meaning their


contents can be modified.

Examples:

person = {"name": "Alice", "age": 25, "city": "New


York"}

scores = {"Math": 90, "English": 85, "Science": 88}

contacts = {"Alice": "123-4567", "Bob": "987-


6543"}
4. SETS
Sets are unordered collections of unique items,
enclosed in curly braces {}. They do not allow
duplicate values and do not maintain a
specific order.

Sets are useful when you need to store distinct


values and perform mathematical set
operations like union, intersection, and
difference.

Examples:

unique_numbers = {1, 2, 3, 4, 5}
fruits = {"Apple", "Banana", "Cherry"}
mixed_set = {"Python", 3.14, 42}
Remember to share
your learning on
LinkedIn

(Tag @10Alytics)

You might also like