0% found this document useful (0 votes)
13 views7 pages

Pluto Academy Day 1

The document provides an introduction to Python, highlighting its simplicity, versatility, and extensive libraries. It covers basic concepts such as variables, data types, input/output functions, operators, and includes practice questions for beginners. The use of the Programiz online compiler is recommended for ease of access and debugging while learning Python.

Uploaded by

raju6301e
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)
13 views7 pages

Pluto Academy Day 1

The document provides an introduction to Python, highlighting its simplicity, versatility, and extensive libraries. It covers basic concepts such as variables, data types, input/output functions, operators, and includes practice questions for beginners. The use of the Programiz online compiler is recommended for ease of access and debugging while learning Python.

Uploaded by

raju6301e
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
You are on page 1/ 7

PLUTO ACADEMY

DAY 1 OF LEARNING PYTHON

What Python is and Why it’s Popular:


Python is a high-level, interpreted programming language created by Guido van Rossum in 1991.

It is widely known for its simplicity and readability, making it beginner-friendly.

Key Features of Python:

1. Easy to Learn and Use: Python’s syntax is straightforward, similar to English.

2. Versatility: Used in web development, machine learning, data science, artificial intelligence,
automation, and more.

3. Extensive Libraries: Python has a vast standard library (e.g., NumPy, Pandas, Matplotlib).

4. Community Support: A large community makes learning resources and problem-solving easy to
find.

We are using the Programiz online compiler to run Python because it offers easy access, is
beginner-friendly, and allows quick debugging. By using this online compiler, we can efficiently focus
on learning and coding without worrying about the technical setup.

How to Write and Run a Python Program:


Example:

print("Hello, World!")

Practice Questions:
1. Write a Python program that prints "Hello, Python!".

2. Install VS Code and run a simple Python program that prints your name.

3. Create a Python program that outputs the message "Learning Python is fun!"

2. Learn Python Basics


Variables and Data Types:
A variable is a container for storing data. Python variables are dynamically typed, meaning you don’t
need to specify the data type explicitly.

Common Data Types in Python:


1. int: Integer values (e.g., 10, -5).

2. float: Decimal values (e.g., 3.14, -0.5).

3. str: String values (e.g., "Hello", "Python").

4. bool: Boolean values (True, False).

Example:

age = 25 # int pi = 3.1415 #

float name = "John" # str

is_raining = True # bool

print(age, pi, name, is_active)

To check the type of the data in python, we have type() function. For example x is a variable. To find
the type of the data of variable x.

print(type(x)) will return the type of the data type of variable x.

print(type(age)) #int

print(type(pi)) #float

print((type(name)) #string

print((type((is_raining)) #boolean

Input and Output:


Input: input() function allows the user to provide input at runtime.

Output:

print() function displays data to the console.

Example: name = input("Enter your name: ") #input

print("Hello, " + name + "! Welcome to Python!") #output

Comments in Python:
Comments help explain your code and are ignored by the Python interpreter.

Single-line comment: Use # at the beginning of the comment.

Multi-line comment: Use triple quotes ''' or """.


Example:

# This is a single-line comment

''' This is a multi-line comment '''

Basic Operators:
Operators are symbols used to perform operations on variables or values. They perform different
operations, such as arithmetic, comparison, logical, etc., depending on the type of operator.

Arithmetic Operators:
These operators are used to perform basic mathematical operations.

+ (Addition): Adds two values.

Example:

a = 10

b=5

print(a + b) # Output: 15

- (Subtraction): Subtracts the second value from the first.

Example: a = 10

b=5

print(a - b) # Output: 5

* (Multiplication): Multiplies two values.

Example: a = 10

b=5

print(a * b) # Output: 50

/ (Division): Divides the first value by the second and returns a float result.

Example: a = 10 b = 5

print(a / b) # Output: 2.0


// (Floor Division): Divides the first value by the second and returns the integer result (ignores the
remainder).

Example: a = 10 b = 3

print(a // b) # Output: 3

% (Modulus): Returns the remainder when the first value is divided by the second.

Example:

a = 10

b=3

print(a % b) # Output: 1

** (Exponentiation): Raises the first value to the power of the second value.

Example:

a= 2
b=3
print(a ** b) # Output:

Comparison Operators:
These operators are used to compare two values and return a boolean result (True or False).

== (Equal to): Returns True if both values are equal.

Example: a = 10 b = 5

print(a == b) # Output: False

!= (Not equal to): Returns True if both values are not equal.

Example: a = 10 b = 5

print(a != b) # Output: True

< (Less than): Returns True if the first value is less than the second.

Example: a = 10 b = 5

print(a < b) # Output: False

> (Greater than): Returns True if the first value is greater than the second.
Example: a = 10 b = 5

print(a > b) # Output: True

<= (Less than or equal to): Returns True if the first value is less than or equal to the second.

Example: a = 10 b = 10

print(a <= b) # Output: True

>= (Greater than or equal to): Returns True if the first value is greater than or equal to the second.

Example: a = 10 b = 5

print(a >= b) # Output: True

Logical Operators
Used to combine conditional statements or perform logical operations.

Operator Description Example Result

and True if both conditions are true (5 > 3) and (4 < 6) True or

True if at least one condition is true (5 > 3) or (4 > 6) True

not Reverses the logical state not (5 > 3) False

Example Code:

a = 10 b = 20 # Logical AND

print(a > 5 and b > 15) # True (both conditions are True)# Logical

OR print(a > 15 or b > 15) # True (one condition is True)

# Logical NOT

print(not(a > 5)) # False (reverses True to False)

Assignment Operators
Used to assign values to variables. They can also combine operations with assignments.
Operator Description Example Result

= Assign a=5 a=5

+= Add and assign a += 3 a=8


-= Subtract and assign a -= 2 a=6

*= Multiply and assign a *= 4 a = 24

/= Divide and assign a /= 3 a = 8.0

**= Exponent and assign a **= 2 a = 64

//= Floor division and assign a //= 5 a = 12

Example Code:

a=5

# Add and assign

a += 3 # a = 5 + 3

print(a) # Output: 8

# Multiply and assign

a *= 2 # a = 8 * 2

print(a) # Output: 16

# Floor division and assign

a //= 3 # a = 16 // 3

print(a) # Output: 5

Membership Operators
Test if a value is present in a sequence like a string, list, or tuple.

Operator Description Example Result

in True if the value exists 'a' in 'apple' True

not in True if the value does not exist 'b' not in 'apple' True

Example Code:

fruits = ["apple", "banana", "cherry"]

# Check if "apple" is in the list

print("apple" in fruits) # Output: True


# Check if "mango" is not in the list

print("mango" not in fruits) # Output: True

5. Identity Operators
Compare the memory locations of two objects.

Operator Description Example Result

is True if objects are the same a is b True

is not True if objects are not the same a is not b False

Example Code:

x = [1, 2, 3]

y = [1, 2, 3]

z=x

# Check if x and z reference the same object

print(x is z) # Output: True

# Check if x and y reference the same object

print(x is y) # Output: False (different objects with same content)

# Check if x and y do not reference the same object

print(x is not y) # Output: True

These operators are fundamental to programming as they allow us to manipulate and compare data,
performing calculations and logical checks.

Practice Questions:
1. Write a Python program to store your age in a variable and print it.

2. Create a program that takes two numbers as input and prints their product.

3. Write a Python program to compare two numbers and print whether the first is greater than the
second.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy