Introduction To Python
Introduction To Python
• Interactive mode:
– Interactive Mode, When we type Python statement, interpreter
displays the result(s) immediately.
• Advantages:
– Working in interactive mode is convenient for beginners
and for testing small pieces of code.
• Drawback:
– We cannot save the statements and have to retype all the
statements once again to re-run them.
• In interactive mode, you type Python programs
and the interpreter displays the result:
• >>> 1 + 1
• 2
• >>>, is the prompt the interpreter uses to
indicate that it is ready for you to enter code.
• If you type 1 + 1, the interpreter replies 2.
• >>> print ('Hello, World!') Hello, World!
• Script mode:
– In script mode, we type python program in a file
and then use interpreter to execute the content of
the file.
– Scripts can be saved to disk for future use.
– Python scripts have the extension.py, meaning
that the filename ends with .py
– Save the code with filename.py and run the
interpreter in script mode to execute the script.
• Integrated Development Learning
Environment (IDLE):
– Is a graphical user interface which is completely
written in Python.
– It is bundled with the default implementation of
the python language and also comes with optional
part of the Python packaging.
• Features of IDLE:
– Multi-window text editor with syntax highlighting.
– Auto completion with smart indentation.
– Python shell to display output with syntax
highlighting
VALUES and DATA TYPES
• Value:
– Value can be any letter ,number or string.
– Eg, Values are 2, 42.0, and 'Hello, World!'. (These
values belong to different datat ypes.)
• Data type:
– Every value in Python has a data type.
– It is a set of values, and the allowable operations
on those values.
Numbers:
▪ Number data type stores Numerical Values.
▪ This data type is immutable [i.e. values/items
cannot be changed].
▪ Python supports integers, floating point
numbers and complex numbers. They are
defined as.
• 2. Sequence:
• A sequence is an ordered collection of items, indexed by positive
integers.
• It is a combination of mutable (value can be changed) and immutable
(values cannot be changed) data types.
There are three types of sequence data type available in Python, they are
– Strings
– Lists
– Tuples
• A String in Python consists of a series or sequence of characters - letters,
numbers, and special characters.
– Strings are marked by quotes:
• single quotes (' ') Eg, 'This a string in single quotes'
• double quotes (" ") Eg, "'This a string in double quotes'"
• triple quotes(""" """) Eg, This is a paragraph. It is made up of multiple lines
and sentences."""
– Individual character in a string is accessed using a subscript
(index).
– Characters can be accessed using indexing and slicing operations
• Indexing: