0% found this document useful (0 votes)
30 views12 pages

Py3 SI Intro

The document discusses the basics of Python including its introduction, applications, compiler vs interpreter, code execution, variables and types, print function, arithmetic operators, string operators, and string formatting. It provides examples to explain each concept.

Uploaded by

Muhammad Waqas
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)
30 views12 pages

Py3 SI Intro

The document discusses the basics of Python including its introduction, applications, compiler vs interpreter, code execution, variables and types, print function, arithmetic operators, string operators, and string formatting. It provides examples to explain each concept.

Uploaded by

Muhammad Waqas
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

sohailimran@yahoo.

com

Introduction
Ref: Web
Introduction
The official introduction to Python is:
Python is an easy to learn, powerful programming language.
It has efficient high-level data structures and a simple but
effective approach to object-oriented programming.
Python’s elegant syntax and dynamic typing, together with
its interpreted nature, make it an ideal language for scripting
and rapid application development in many areas on most
platforms.

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 1


Top Analytics, Data Science, ML

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 2


Application

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 3


Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 4
Compiler vs Interpreter

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 5


Code execution

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 6


Variables and Types
Python is completely object oriented, and not "statically typed". You do not need to
declare variables before using them, or declare their type. Every variable in Python
is an object.

Numbers
Python supports two types of numbers - integers and floating point numbers. (It also
supports complex numbers, which will not be explained in this tutorial).

Strings
Strings are defined either with a single quote or a double quotes.

The difference between the two is that using double quotes makes it easy to include
apostrophes (whereas these would terminate the string if using single quotes)

Assignments can be done on more than one variable "simultaneously" on the same
line like this
a, b = 3, 4

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 7


print
To print a string in Python, just write:

print("Hello World")

name = “Python”
print("Hi there,", name)

Python also supports multiplying strings to form a string with a repeating


sequence:
print("5"*6)

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 8


Basic Operators: Arithmetic
Just as any other programming languages, the addition, subtraction, multiplication,
and division operators can be used with numbers.

number = 1 + 2 * 3 / 4.0
print(number)

Try to predict what the answer will be. Does python follow order of operations?
Another operator available is the modulo (%) operator, which returns the integer
remainder of the division. dividend % divisor = remainder.

remainder = 11 % 3
print(remainder)

Using two multiplication symbols makes a power relationship.

squared = 7 ** 2
cubed = 2 ** 3
print(squared)
print(cubed)

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 9


Basic Operators: String
name = input("Enter name: ")
Output:
Enter your name: Python

print(name)
Output:
Python

Python supports concatenating strings using the addition operator:

helloworld = "hello" + " " + "world"


print(helloworld)

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 10


String Formatting
Python uses C-style string formatting to create new, formatted strings.
The "%" operator is used to format a set of variables enclosed in a "tuple" (a fixed size list), together
with a format string, which contains normal text together with "argument specifiers", special symbols
like "%s" and "%d".
Let's say you have a variable called "name" with your user name in it, and you would then like to
print(out a greeting to that user.)

# This prints out "Hello, John!"


name = "John"
print("Hello, %s!" % name)
Output:
Hello, John!

To use two or more argument specifiers, use a tuple (parentheses):

# This prints out "John is 23 years old."


name = "John"
age = 23
print("%s is %d years old." % (name, age))

Output:
John is 23 years old.

Sohail IMRAN ‫ﺳﻬﯿﻞﻋﻤﺮﺍﻥ‬ 11

You might also like