Python Basics-1
Python Basics-1
Problem Solving
Python Basics
● Steps:
1) Farmer crosses with goat
2) Farmer returns alone
3) Farmer crosses with cabbage
4) Farmer returns with goat
5) Farmer crosses with wolf
6) Farmer returns alone
7) Farmer crosses with goat
8) They are all on the other side
Programming Paradigms
• A programming paradigm is a style, or “way,” of programming.
• It does not refer to a specific language, but rather it refers to the way you
program.
Programming Paradigms
1. Imperative programming paradigm: It is one of the oldest programming
paradigms.
• It features a close relation to machine architecture.
• The paradigm consists of several statements, and after the execution of all of
them, the result is stored.
• It’s about writing a list of instructions to tell the computer what to do step by
step.
• Examples of Imperative programming paradigm: C, Fortran
• Divided into three broad categories: Procedural, OOP, and Parallel
processing.
Imperative programming paradigm
A. Object oriented programming
• The program is written as a collection of classes and objects which are meant
for communication.
• The smallest and basic entity is an object and all kind of computation is
performed on the objects only.
• Advantages:
• Data security
• Inheritance
• Code reusability
• Flexible and abstraction is also present
• Examples of Object Oriented programming paradigm: Java, C++, Visual Basic
.NET, Ruby, Python
Imperative programming paradigm
B. Procedural programming paradigm
• This paradigm emphasizes procedure in terms of underlying machine model.
• Imperative programming with procedure calls
• Examples – C, C++, Java, Pascal
● Keywords are some predefined and reserved words in python that have special
meanings. Keywords are used to define the syntax of the coding.
● To display the keywords, type help() in the Python shell, and then type keywords
(type 'q' to quit).
Identifier
● Rules to be followed:
○ Can only contain alphanumeric characters and underscores (a-z, A-Z, 0-9, _)
○ Must start with letters but cannot start with a number
○ Names are case-sensitive
○ Name cannot be a keyword
○ Should be one word with no spaces in between
○ Python does not allow special characters
Identifier
Literal
● Literals in Python can be defined as numbers, text, or other data that represent
values to be stored in variables.
● Raw data assigned to variables, or, constants used while programming
○ Numeric Literals
○ String Literals
○ Boolean Literals
○ Literal Collections
○ Special Literals
Literal
• A numeric literal is a literal containing only the digits 0–9, an optional sign character,
and a possible decimal point.
• Commas are never used in numeric literals
• Floating Point: used to produce a specific number of decimal places
How to encode(represent) character within
a computer ???
String Literal
● String literals -> delimited (surrounded) by a matching pair of either single (') or
double (") quotes.
● May also contain quote characters as long as different quotes are used to delimit:
"Jennifer Smith's Friend" Correct
Incorrect
Literal