0% found this document useful (0 votes)
16 views26 pages

Introduction To Python (Lab 1)

This document provides an introduction to Python, covering topics like environment setup using Anaconda, Python code using Jupyter Notebook and Spyder IDEs, basic syntax like comments and data types, and variables including numbers, strings, lists, tuples and dictionaries.

Uploaded by

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

Introduction To Python (Lab 1)

This document provides an introduction to Python, covering topics like environment setup using Anaconda, Python code using Jupyter Notebook and Spyder IDEs, basic syntax like comments and data types, and variables including numbers, strings, lists, tuples and dictionaries.

Uploaded by

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

Introduction to Python

Why Python ? Introduction to


Python

Eng. Hadeer Mostafa Lab (1) 2


Introduction to
Environment Setup Python

qDownload Anaconda for python 3.8 version (64/32 bit)


§ https://www.anaconda.com/download/

Eng. Hadeer Mostafa Lab (1) 3


Introduction to
Let’s Start Python

LAB 1

Eng. Hadeer Mostafa Lab (1) 4


Introduction to
Python Code using Anaconda Navigator Python

We have 2 ways, the first one is done by following the next steps:
1. Open Anaconda navigator
2. Go to Jupyter and open it
3. Any time we want to make a new Python project, we do the following
1. Go to File tab => new notebook => Python3
2. To write a new statement click Enter
3. To run your code click Enter + Shift
4. To save your code go to and click on it.

Eng. Hadeer Mostafa Lab (1) 5


Introduction to
Python Code using Anaconda Navigator Python

The second one is done by the following steps:


1. Open Anaconda navigator

2. Go to spyder and open it


3. Any time we want to make a new Python project, we do the following

1. Go to File tab => new file or click on

2. To run your code click on

3. To save your code go to file => save as or

Eng. Hadeer Mostafa Lab (1) 6


Introduction to
Basic Syntax Python

Procedure Name Task


print Prints the given text message or expression value on the
console, and moves the cursor down to the next line.
qExamples:

Eng. Hadeer Mostafa Lab (1) 7


Introduction to
Basic Syntax Python

qQuotations

Eng. Hadeer Mostafa Lab (1) 8


Introduction to
Basic Syntax Python

qQuotations (cont.):

Eng. Hadeer Mostafa Lab (1) 9


Introduction to
Basic Syntax Python

qComment:
üWe use # symbol to insert comment in python script.

üNote: we can use the triple double quotation (“ “ “ any thing ” ” ”) as a comment

Eng. Hadeer Mostafa Lab (1) 10


Introduction to
Basic Syntax Python

qMulti Line Statement:

üWe use \ symbol to write multi line statement in python script.

§ Example

Eng. Hadeer Mostafa Lab (1) 11


Introduction to
Basic Syntax Python

qMultiple Statements on a Single Line:


üWe use ; symbol to write multiple statements on a single line in python script.

§ Example

Eng. Hadeer Mostafa Lab (1) 12


Introduction to
Basic Syntax Python

qLines and Indentation:


ü Python provides no braces to indicate blocks of code for class and function
definitions or flow control.
ü Blocks of code are denoted by line indentation.
ü The number of spaces in the indentation is variable, but all statements within the
block must be indented the same amount.

Eng. Hadeer Mostafa Lab (1) 13


Introduction to
Basic Syntax Python

qMultiple Assignment:

Eng. Hadeer Mostafa Lab (1) 14


Introduction to
Data Types and Variables Python

qPython has five standard data types:

Numbers
Dictionary

Tuple String

List

Eng. Hadeer Mostafa Lab (1) 15


Introduction to
Data Types and Variables Python

§ In python there is no data type declaration before variable creation.


§ The variable acquires the data type from the value assigned to it.

Eng. Hadeer Mostafa Lab (1) 16


Introduction to
Data Types and Variables: Numbers Python

qPython supports three different numerical types:

Eng. Hadeer Mostafa Lab (1) 17


Introduction to
Data Types and Variables: String Python

qStrings in Python are identified as a contiguous set of characters represented in the


quotation marks.

Eng. Hadeer Mostafa Lab (1) 18


Introduction to
Data Types and Variables: List Python

Eng. Hadeer Mostafa Lab (1) 19


Introduction to
Data Types and Variables: Tuple Python

§ A tuple is another sequence data type that is similar to the list. A tuple
consists of a number of values separated by commas. Unlike lists, however,
tuples are enclosed within parenthesis.

§ The main difference between lists and tuples are − Lists are enclosed in
square brackets [ ] and their elements and size can be changed, while tuples
are enclosed in parentheses ( ) and cannot be updated. Tuples can be thought
of as read only lists.
Eng. Hadeer Mostafa Lab (1) 20
Introduction to
Data Types and Variables: Tuple Python

Eng. Hadeer Mostafa Lab (1) 21


Introduction to
Data Types and Variables: Dictionary Python

§ Dictionary is a sequence data type, each item consists of pair of key and value.

§ The key has unique value.

§ Each key is separated from its value by a colon (:), the items are separated by commas,

and the whole thing is enclosed in curly braces {}

§ The value of each item can be retrieved by using its key instead of index as list and tuple.

Eng. Hadeer Mostafa Lab (1) 22


Introduction to
Data Types and Variables: Dictionary Python

Eng. Hadeer Mostafa Lab (1) 23


Introduction to
Data Types and Variables: Dictionary Python

Eng. Hadeer Mostafa Lab (1) 24


Introduction to
Data Types and Variables: Dictionary Python

Eng. Hadeer Mostafa Lab (1) 25


Introduction to
Python

Eng. Hadeer Mostafa Lab (1) 26

You might also like