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

Lecture 1 - Intro To Python - Part 1

Uploaded by

cobahe2820
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 views

Lecture 1 - Intro To Python - Part 1

Uploaded by

cobahe2820
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/ 12

Introduction

to Python
Part 1
COMP 8347
Usama Mir
[email protected]
Python Basics

 Topics
 Introduction

 Why Python

 Overview of IDLE

 Input and Print in Python

2
Why Python?

java

py

Source: https://trends.google.com/trends/explore?date=all&geo=US&q=%2Fm%2F05z1_,%2Fm%2F07sbkfb

3
Why Python?

Developed by Guido Van Simple syntax and easy It emphasizes


Rossum to learn readability

Used for:
•RAD and Scripting Supports object-
What we see today on
•Process text oriented programming:
our devices is because
•Display images with classes and
of Python
•Making calculations and multiple inheritance.
predictions

Dynamically typed
language: Do not have Python vs. Java?
to assign variable types

4
Notable Features of Python

 Elegant syntax and easy to use: programs easier to read.


 Large standard library: supports many common
programming tasks e.g. connecting to web servers,
regular expressions, file I/O.
 A bundled development environment called IDLE.
 Runs on different computers and operating systems:
Windows, MacOS, many brands of Unix, OS/2, ...
 Free software: Free to download or use Python - the
language is copyrighted it's available under an open
source license.

5
Indentation
 Python does not use brackets to structure code, instead it uses
whitespaces
 Tabs are not permitted.
 Four spaces are required to create a new block,
 To end a block simply move the cursor four positions left.
 An example: Nested loop

for i in range(5):
for j in range(10):
print(j)
print(i)
print('done')

6
IDLE

 IDLE: Basic IDE that comes with


Python
 Should be available from Start
Menu under Python program
group.
 Main "Interpreter" window.
 Allows us to enter
commands directly into
Python
 As soon as we enter in a
command Python will
execute it display the
result.
 '>>>' signs act as a
prompt.

7
IDLE EXAMPLE

8
Numeric Data Types

 int: represents positive and negative whole numbers.


 Written without a decimal point
 e.g., 5, -2, 5555555555, 7

 float: written with a decimal point


 e.g., 3.0, 5.8421, 0.0, -32.5 etc.

 Rest in part 2…..

9
Arithmetic Operators
 Basic arithmetic operators: + (addition), - (subtraction), *
(multiplication), / (division)

• / (division) produces floating point 15/3 → 5.0


value
• // (integer division) truncates any 25//3 → 8
fractional part
• % (remainder) gives the remainder after 25%3 → 1
integer division.
• Augmented assignment operators: +=, -
=, *=, /=

10
Basic Input/Print
 Built-in input() function accepts input from user.
 Takes optional string argument to print on console
 Waits for user to type response and hit Enter
 If no text, user just hits enter: return empty string
 Otherwise, return string containing entered text
 Example: i = input(“Enter an integer: ”)

 Built-in print() function for output.


 Example: print(“int = ”, i)

11
References

 Slides from Dr. Arunita and Dr. Saja


 https://www.linkedin.com/learning/python-quick-
start/python-vs-
java?autoAdvance=true&autoSkip=true&autoplay=true&
resume=false&u=56973065
 https://www.coursera.org/articles/python-vs-java

12

You might also like