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

UNIT I - Introduction To Python

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

UNIT I - Introduction To Python

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

UNIT I

Introduction to Python
Why Programming?
The computer understands 1s and 0s only. To communicate a real-life problem
to the computer, you need to create a speci c type of text, called a source code
or a human readable code, that software can read and then process to the
computer in 1s and 0s

Terms De nition
A sequence of instructions that designate(select) how
Program
to execute a computation(calculation)
Taking a task and writing it down in a programming
Programming language that the computer can understand and
execute
fi
About Python….
Monty python’s flying circus- British Comedy Movie
Why Python?
Python is an open-source, general-purpose and high-level programming language.

Open-source means it is free. Python has a large


and active scienti c community with access to
Open-source software
the software’s source code and contributes to its
(OSS)
continuous development and upgrading,
depending on users’ needs
There is a broad set of elds where Python could
General-purpose be applied – web programming, analysis of
nancial data, analysis of big data, and more
High-level languages employ syntax a lot closer
High-level to human logic, which makes the language easier
to learn and implement.
fi
fi
fi
Applications…..
Python Fundamentals:Rules for variable names
❖ Do not start the names with a number.
❖ Do not use spaces in names, use _ instead.
❖ Do not use any of these symbols in names: :'",<>/?|\!@#%^&*~-+
❖ Inculcate the best practice or writing names in lowercase with underscores.
❖ Avoid using Python built-in keywords, such as list and str.
❖ Avoid using the single characters l (lowercase letter el), O (uppercase letter
oh), and I (uppercase letter eye) as they can be confused with 1 and 0.
Python Fundamentals: Python Variables and Data Types
Variables are used to store the information
Python Fundamentals: Numbers and Boolean Values

Positive or negative whole numbers without a


Integer decimal point
Example: 5, 10, -3, -15

Real numbers. Hence, they have a decimal point


Floating point ( oat)
Example: 4.75, -5.50, 11.0

Boolean value Example: True, False


fl
Python Fundamentals: Strings
Strings are text values composed of a sequence of characters.
Python Fundamentals: Basic Python Syntax
Arithmetic Operators

Operator Description Operator Description

+ Addition % Returns remainder

- Subtraction * Multiplication

Performs power
/ Division **
calculation
Python Fundamentals: Basic Python Syntax
The Double Equality Sign Reassign Values
Dynamic typing

❖ Python uses dynamic typing,


meaning we can reassign variables
to different data types.
❖ This makes Python very exible in
assigning data types; it differs from
other languages that are statically
typed.

fl
Python Fundamentals: String indexing
Continuation

Assign a String
Python Fundamentals: String Indexing Elements
Python Fundamentals: String Indexing Elements
Python Fundamentals: String Slicing
Python Fundamentals: String Slicing
Python Fundamentals: String Slicing
Python Fundamentals: String Properties
Python Fundamentals: String Properties
Python Fundamentals: Basic built-in string methods
Writing to the screen

❖ open() returns a le object, and is most commonly used with two arguments:
open( lename, mode).
❖ Example: >>> f = open('work le', ‘w’)
❖ The rst argument is a string containing the lename.
❖ The second argument is another string containing a few characters
describing the way in which the le will be used.
fi
fi
fi
fi
fi
There are three ways of writing values
❖ Expression statements:
❖ Expression statements are used (mostly interactively) to compute and write a value, or
(usually) to call a procedure.
❖ Print() function:
❖ The print function in Python is a function that outputs to your console window
whatever you say you want to print out
❖ Write() method:
❖ he method write() writes a string ‘str’ to the le. There is no return value. Due to
buffering, the string may not actually show up in the le until the ush() or close()
method is called.

You might also like