0% found this document useful (0 votes)
3 views25 pages

Introduction to Python Programming

The document provides an introduction to computer programming using Python, highlighting its features, syntax, and data types. It covers built-in and user-defined data types, including examples of integers, floats, strings, lists, tuples, dictionaries, and sets. Additionally, it includes practical problems for readers to practice their understanding of Python programming concepts.
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)
3 views25 pages

Introduction to Python Programming

The document provides an introduction to computer programming using Python, highlighting its features, syntax, and data types. It covers built-in and user-defined data types, including examples of integers, floats, strings, lists, tuples, dictionaries, and sets. Additionally, it includes practical problems for readers to practice their understanding of Python programming concepts.
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

INTRODUCTION

TO COMPUTER
PROGRAMMING
TOPICS

1 2 3 4 5
Introduction Data Types Operators Basic Conditional
Input-Output Execution
operations

2 Presentation title 20XX


Introduction
Python is a high-level programming
language. Open source and community
driven. Source can be compiled or run
just-in-time. Similar to perl, tcl, ruby

3
•Unlike AML and Avenue, there is a considerable
base of developers already using the language
•“Tried and true” language that has been in
development since 1991
•Can interface with the Component Object Model
WHY
(COM) used by Windows
•Can interface with Open Source GIS toolsets
•It has simplified syntax and not complicated,
PYTHON?
which gives more emphasis on natural language.
EXAMPLE SYNTAX

PYTHON PRINT STATEMENT


Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022,
16:36:42) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more
information.
>>> print("Hello World")
Hello World
>>>

5 Presentation title 20XX


PYTHON INTERFACE
IDE
An integrated development environment (IDE) is a software application that
provides comprehensive facilities for software development.
- [Link] is an online compiler and debugger tool for C, C++, Python,
PHP, Ruby, C#, OCaml, VB, Perl, Swift, Prolog, Javascript, Pascal, COBOL,
HTML, CSS, JS. Code, Compile, Run and Debug online from anywhere in world.
(code. compile. run. debug. share.)
- PyCharm is a dedicated Python Integrated Development Environment (IDE)
providing a wide range of essential tools for Python developers, tightly integrated to
create a convenient environment for productive Python, web, and data science
development.
- Pydroid 3, your pocket Python interpreter, empowers you to write, run, and
experiment with Python code from your mobile device.
6 20XX
Example Program
IDLE helps you program in
Python by
•color-coding your program
code
•debugging
•auto-indent
•interactive shell
Example
Program
Python is case-sensitive, which means, for
example, Name and name have different
meanings

The standard is to use English names in


programming

Syntax The first letter of a variable, function, or class must

and Rules be one of the letters (a-z) or (A-Z). Numbers or


special characters such as & and% are not allowed

in Python Python is sensitive to indentations, that marks a


block segment in your code

Functions begin with lowercase


Classes begins with a capital letter
“ There are reserved words,
such as and, if, else, break,
import, and more, which are
not allowed in naming
variables.

10 Presentation title

20XX
11 Presentation title 20XX
PYTHON DATA TYPE
Data type in python represents the data store in memory or variable.
Python, support two types of data types:

• Built-In Data Types: The data types, which is already available in a


python programming language is called Built-In data types.

• User-Defined Data Types: The data types, which can be created by the
programmer itself are called User-defined data types.

14 20XX
PYTHON DATA TYPE
Numbers: The Number data type is used to stores numeric values.
String: The string data type is used to stores the sequence of characters.
Tuple: Tuple data type is used to stores a collection of different data types
of elements, and it is immutable.
List: List data type is used to store the collection of different data types of
elements, and it is mutable.
Set: Set data type is used to store different data types of elements; it is
mutable and stores unique elements.
Dictionary: Dictionary data type is used to store a collection of different
data types of elements in the form of key-value pairs; it is mutable and
stores the unique key.
15 20XX
Data type Description Example
int To store integer values n = 20
float To store decimal values n = 20.75
To store complex numbers (real and
complex n = 10+20j
imaginary part)
str To store textual/string data name = 'Jessa'
bool To store boolean values flag = True
list To store a sequence of mutable data l = [3, 'a', 2.5]
tuple To store sequence immutable data t =(2, 'b', 6.4)
dict To store key: value pair d = {1:'J', 2:'E'}
set To store unorder and unindexed values s = {1, 3, 5}
Note – type() function is used to determine the type of data
type.
16 20XX
NUMERIC PYTHON DATA TYPE
Integers
An integer is a whole number with no decimal places. For example, 1 is an integer,
but 1.0 isn’t.
Floating-Point Numbers
A floating-point number, or float for short, is a number with a decimal place. 1.0 is a
floating-point number, as is -2.75.
Complex Numbers
Complex number is a number with two distinct components: a real part and an
imaginary part.
To create a complex number in Python, you simply write the real part, then a plus
sign, then the imaginary part with the letter j at the end:
n = 1 + 2j
17 20XX
NUMERIC PYTHON DATA TYPE

18 20XX
SEQUENCE PYTHON DATA
STRING
TYPE
In Python, the text data type is called "string" and is abbreviated as str. Using a
string data type means that everything is treated as text, even the numbers.
Important: Mathematical operations cannot be performed on the string data type; you'll
need a numeric data type for that.
• If you want something to be treated as a string, i.e. text, put single quotation marks
around it, 'like this'. You can also use double quotation mark.

19 20XX
SEQUENCE PYTHON DATA
Lists
TYPE
are just like the arrays, declared in other languages which is a ordered collection of
data. It is very flexible as the items in a list do not need to be of the same type.
Creating List
Lists in Python can be created by just placing the sequence inside the square brackets[].
Tuple
Just like list, tuple is also an ordered collection of Python objects. The only
difference between tuple and list is that tuples are immutable i.e. tuples cannot be
modified after it is created. It is represented by tuple class.
Creating Tuple
In Python, tuples are created by placing a sequence of values separated by ‘comma’ with or
without the use of parentheses for grouping of the data sequence. Tuples can contain any number
of elements and of any datatype (like strings, integers, list, etc.).
20 20XX
OTHER PYTHON DATA TYPE
Dictionary
Dictionary in Python is an unordered collection of data values, used to store data
values like a map, which unlike other Data Types that hold only single value as an
element, Dictionary holds key:value pair. Key-value is provided in the dictionary to
make it more optimized. Each key-value pair in a Dictionary is separated by a colon
:, whereas each key is separated by a ‘comma’.
Set
In Python, Set is an unordered collection of data type that is iterable, mutable and
has no duplicate elements. The order of elements in a set is undefined though it may
consist of various elements.

21 20XX
BOOLEAN PYTHON DATA TYPE
A Boolean data type is a value that can only be either true or false (these
are known as Boolean values).
• A true Boolean value might indicate that the object is valid (e.g. an email address
has been typed correctly). A false Boolean value indicates that the object is invalid
and has not been done correctly (e.g. you’ve forgotten to fill out a required field).

22 20XX
LET’S DO THIS
Problem 1: Integer and Float Operations
• Declare two variables, num1 and num2, with values 10 and 5.5 respectively.
• Calculate the sum, difference, product, and quotient of these two numbers.
• Print the results in a formatted manner.
Problem 2: String Manipulation
• Declare a string variable name with your name.
• Declare another string variable country with the name of your country.
• Concatenate the two strings and store the result in a variable message.
• Print the message variable.
LET’S DO THIS
Problem 3: Type Conversion
• Declare a variable number_str with the string value '42'.
• Convert number_str to an integer and store the result in a variable number_int.
• Print the type of number_int.
Problem 4: List Operations
• Create a list numbers with the values 3, 7, 1, 8, and 4.
• Append the value 5 to the list.
• Sort the list in ascending order.
• Calculate the sum of all the elements in the list.
• Print the sorted list and the sum.
LET’S DO THIS
Problem 5: Dictionary Operations
• Create a dictionary person with keys 'name', 'age', and 'city' with corresponding
values.
• Add a new key-value pair 'country' with the value of your country.
• Print the updated dictionary.
Problem 6: Set Operations with Mixed Types
• Create a set mixed_set with elements of different types: int, float, and string.
• Print the set.
• Convert the set to a list and print the result.

You might also like