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

CS NOTES

The document provides an overview of various data types in Python, including strings, integers, floats, characters, and Booleans, along with examples of their usage. It also explains assignment in Python, the input and print functions, and introduces common Python libraries like NumPy and Pandas. Additionally, it covers operators and includes sample conditional statement programs for finding the largest number and evaluating exam results.

Uploaded by

arhamrahman558
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

CS NOTES

The document provides an overview of various data types in Python, including strings, integers, floats, characters, and Booleans, along with examples of their usage. It also explains assignment in Python, the input and print functions, and introduces common Python libraries like NumPy and Pandas. Additionally, it covers operators and includes sample conditional statement programs for finding the largest number and evaluating exam results.

Uploaded by

arhamrahman558
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

CS notes

A data type specifies the type of value a variable can hold, such
as numbers, text, or logical values like true/false.
 What is a string data type?
A string(str) is a data type that represents text. It is a sequence
of characters enclosed in single (' ') or double (" ") quotes.
For example:
 "Hello"
 'Python'
Strings can include letters, numbers, spaces, and symbols. You
can perform operations like concatenation (joining) or slicing
(extracting parts) with strings.
Taking input: a=str(input(“enter word”))
Declaration: a=“A”
 What is an Integer?
An integer (int) is a data type that represents whole numbers,
both positive and negative, without decimal points.
For example:
 5
 -10
 0
Integers can be used for arithmetic operations like addition,
subtraction, multiplication, and division.
Taking input: a=int(input(“enter number”))
Declaration: a=12
 What is float ?
A float is a data type that represents numbers with decimal
points.
For example:
 3.14
 -0.001
 2.5
Floats are used when precision with decimal values is needed,
such as in measurements or calculations.
Taking input: a=float(input(“enter number”))
Declaration: a=3.14159
 What are characters?
In programming, a character is a single letter, number, or
symbol. It is typically stored as a string of length 1, enclosed in
single or double quotes.
For example:
 'A'
 '9'
 '#'
Characters are often used to represent individual elements in a
string or to manipulate text.
Taking input: a=char(input(“enter word”))
Declaration: a=“hi”
 What is Boolean?
A Boolean is a data type that represents one of two possible
values: True or False. It is used to perform logical operations and
control the flow of programs.
For example:
 True
 False
Booleans are commonly used in conditions, like in if statements,
to check whether something is true or false.
Q. What is assignment and how to assign values in
python?
Ans : Assignment means to assign or set values to a variable.
Steps to assign variable
 We need to name the variable.
 By using the assignment operators the value will be given.
As example : a=5

Variable value

Q. In how many ways can we assign a variable?


Ans: Two ways
Assigning a static value. This value needs to be changed
everytime before running a code.
Example: a=5
By using the input function for taking different values
without entering the code.
Example : a=int(input(“enter number”))
1. input() Function
The input() function lets the user type something into the
program. It always takes the input as a string, even if numbers
are entered. This function is useful for getting user input like
names, ages, or other details.
Example:
name = input("What is your name? ")

2. print() Function
The print() function is used to display messages, numbers, or
variables on the screen. By default, each print() statement moves
to a new line. You can print text, numbers, or a combination of
both.
Example:
print(“bye")

Python libraries
What is a Python Library?
A Python library is a collection of ready-made code that helps
you perform specific tasks without writing everything from
scratch. Libraries save time and make programming easier.

Common Python Libraries


1. NumPy
o Used for working with numbers and arrays.
o Helps with calculations like addition, multiplication.
2. Pandas
o Used for organizing and analyzing data.
o Provides tools like tables to work with large data easily.
3. Matplotlib
o Used for creating charts and graphs.
o Helps visualize data with bar graphs, line charts, and
more.
4. Scikit-learn
o A library for building machine learning models.
o Used for tasks like predicting or grouping data.
5. Requests
o Helps connect your program to the internet.
o Used to send or fetch data from websites .
 What are operators?
Ans: Operators in Python
Operators are symbols that perform actions on values, like math
or comparisons.
Types of Operators:
🔹 Arithmetic Operators → Do math operations.
+, -, *, /, %, //, **
🔹 Comparison Operators → Compare values.
==, !=, >, <, >=, <=
🔹 Logical Operators → Combine conditions.
and, or, not
🔹 Assignment Operators → Assign values.

 What is a variable?
Ans: A variable is a name that holds a value, like text or
numbers. It helps store and use data in a program . It
changes depending on the context of the program.
 Conditional statement programs

 Write a program that will


 Take 3 numbers as input
 Print the largest number
Code-
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
num3 = int(input("Enter third number: "))

if num1 >= num2 and num1 >= num3:


print("num1 is the largest")
elif num2 >= num1 and num2 >= num3:
print("num2 is the largest")
else:
print("num3 is the largest")

 Take your exam result as input and show the output as


following.
 If mark is >60 print try hard
 If mark is <60 print good
 If mark is <80 print excellent
Code-
mark = float(input("Enter your exam mark: "))
if mark > 80:
print("Excellent")
elif mark > 60:
print("Try hard")
else:
print("Good")

You might also like