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

PythonLecture 01

Uploaded by

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

PythonLecture 01

Uploaded by

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

What is Programming

Programming is the process of creating instructions that a computer can understand


and execute. These instructions, called code, are written in a programming language.
There are many different programming languages, each with its own syntax and
semantics.

Difference between High Level and Low-Level Language


• High-level languages are more human-readable and easier to learn than low-
level languages. They are designed to be independent of the specific computer
architecture they are running on. Python is an example of a high-level language.
• Low-level languages are closer to the machine code that the computer
understands. They are more difficult to learn and program with, but they give the
programmer more control over the hardware. Assembly language is an example
of a low-level language.
What is Python and where it is used with an example

Python is a high-level, general-purpose programming language that is known for its


readability and ease of use. It is widely used in a variety of applications, including:

• Web development: Python is used to develop web applications using


frameworks like Django and Flask.
• Data science: Python is a popular language for data science due to its powerful
libraries like NumPy, pandas, and Matplotlib.
• Machine learning: Python is a popular language for machine learning due to its
libraries like scikit-learn and TensorFlow.
• Automation: Python can be used to automate tasks on your computer.

Here is a simple Python program that prints "Hello, World!":

Python
print("Hello,World!")
Why Python is simple
Python is considered
simple for several
reasons:

• Readability: Python code is known for its readability, thanks to its use of clear
and concise syntax. It uses indentation to define code blocks, which makes the
code visually clear and easy to follow.
• Simplicity: Python has a relatively simple syntax with few keywords. This makes
it easier to learn and use compared to other programming languages.
• Large standard library: Python has a large standard library that includes a wide
variety of modules and functions for common tasks. This means that you don't
have to write a lot of code from scratch to get started.
Developed by whom

Python was developed by Guido van Rossum in the late 1980s.

Why Python is portable

Python is portable because it is a high-level language. This means that Python code
can be run on any computer that has a Python interpreter installed, regardless of the
underlying operating system or hardware architecture. The Python interpreter translates
the Python code into machine code that the specific computer can understand.

Hello World Program explained


The print function is used to output data to the console. In the code print("Hello,
World!"), the string "Hello, World!" is passed as an argument to the print function.

The print function then outputs the string to the console. Details

about Python Character set

The Python character set is a superset of the ASCII character set. It includes the
following characters:
• Letters (uppercase and lowercase)
• Digits (0-9)
• Special symbols (e.g., $, %, ^, &, *, (,), -, +, =, {,}, [])
• White spaces (e.g., space, tab, newline)
• Other characters (e.g., ©, ™, ®)
Variables

A variable is a named storage location in memory that can hold a value. You can
declare a variable in Python by assigning a value to it. The value can be of any data
type.

Rules for Identifiers

An identifier is a name given to a variable, function, class, or module. Here are the rules
for identifiers in Python:

• An identifier can start with a letter (uppercase or lowercase) or an


underscore (_).
• After the first character, an identifier can contain letters, digits, or
underscores.
• Identifiers are case-sensitive (e.g., name is different from Name).
• Keywords (e.g., if, else, for, while) cannot be used as identifiers.

Data types in Python

Python has a variety of built-in data types, including:

• Integers (e.g., 1, 2, 3)
• Floating-point numbers (e.g., 3.14, 1.0e-5)
• Strings (e.g., "Hello, world!", 'This is a string')
• Booleans (True or False)
• Lists (ordered collections of items)
• Tuples (immutable ordered collections of items)
• Dictionaries (collections of key-value pairs)
Arithmetic Operators
Python supports the following arithmetic operators:
• Addition (+)
• Subtraction (-)
• Multiplication (*)
• Division (/)
• Floor division (//)
• Modulo (%)
• Exponentiation (**)

Highlighted will be discussed later!

The modulo operator, often represented by %, is like a division machine that


only cares about the leftovers. It calculates the remainder when you divide one
number (dividend) by another (divisor).

For example, 7 % 3 is 1, because 7 divided by 3 leaves a remainder of 1.

Floor Division (//) vs. floor() function


• Floor division (//) performs integer division and discards the remainder. For
example, 5 // 2 equals 2.
• The floor() function is a built-in function that also returns the floor of a division.
However, it can be used with any data type that supports division, not just
integers. For example, floor(5.2) equals 5.
Typed Languages vs. Untyped Languages
Programming languages can be classified into typed and untyped languages based on
how they handle data types.
• Typed languages: In typed languages, variables have a specific data type
associated with them. This data type determines the values that the variable can
hold and the operations that can be performed on it. There are two main
categories of typed languages:
Implicit vs. Explicit Typing
• Implicit typing: In implicitly typed languages, the data type of a variable is
inferred by the compiler or interpreter based on the value assigned to it. Python is
an example of an implicitly typed language.
• Explicit typing: In explicitly typed languages, the programmer must declare the
data type of a variable explicitly. This can be done at the time the variable is
declared. Statically typed languages typically require explicit typing.
Here's a table summarizing the key differences between implicit and explicit typing:
Feature Implicit Typing Explicit Typing

Data type declaration Inferred by compiler/interpreter Declared by programmer

Example language Python Java, C++, C#

Improves code clarity and


Advantages More concise code, easier for beginners
reduces errors

Can lead to runtime errors if incompatible


Disadvantages data types are used Can be more verbose

Examples of code we learnt on the first day!


A, B, C, D = "Naisha", "@", 3, 2

print(((C + D) * 2) * B) # Output: @@@@@@@@

**Explanation:**
- `(C + D) * 2` evaluates to 10 (5 multiplied by 2).
- `10 * B` concatenates the string "@" ten times

You might also like