Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Getting-starting With Python

This document provides an introduction to Python, highlighting its features such as simplicity, cross-platform compatibility, and support for both procedural and object-oriented programming. It covers installation steps, basic syntax, data types, operators, control structures, and functions in Python. The document serves as a foundational guide for beginners looking to learn Python programming.

Uploaded by

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

Getting-starting With Python

This document provides an introduction to Python, highlighting its features such as simplicity, cross-platform compatibility, and support for both procedural and object-oriented programming. It covers installation steps, basic syntax, data types, operators, control structures, and functions in Python. The document serves as a foundational guide for beginners looking to learn Python programming.

Uploaded by

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

CLASS–11 COMPUTER SCIENCE

NOTES
GETTING STARTED WITH PYTHON
Introduction to Python
Python is a high-level, interpreted programming language known for its simplicity and readability. t is an ideal
language for beginners, offering a clear and easy-to-understand syntax. Python supports both procedural and
object-oriented programming paradigms, making it versatile and widely used in fields such as web
development, data science, automation, and artificial intelligence.
Features of Python
1. SimpleandEasytoLearn:Python’ssyntaxisclearandconcise,resemblingplainEnglish,whichmakesiteasier for
beginners to grasp.
2. InterpretedLanguage:Pythoncodeisexecutedlinebyline,whichsimplifiesdebuggingandreducescomplexity in
program execution.
3. Cross-Platform:PythonprogramscanrunonvariousoperatingsystemslikeWindows,macOS,andLinux
without needing modification.
4. ExtensiveLibraries:Pythonhasarichsetoflibrariesthatprovidepre-writtencodeforvarioustasks,making
development faster.
5. Open-Source:Pythonisfreetouseanddistribute,includingforcommercialpurposes.
6. DynamicTyping:VariablesinPythondonotneedexplicitdeclarationofdatatypes;Pythondeterminesthetype at
runtime.
7. Object-Oriented:Pythonsupportsobject-orientedprogramming(OOP),allowingforreusabilityofcodeand
better data organization.
Installing Python
1. Installation Steps:
o DownloadthelatestversionofPythonfrompython.org.
o Followtheinstallationinstructionsforyouroperatingsystem(Windows,macOS,orLinux).
o EnsurethatthePythonexecutableisaddedtothesystem’sPATHduringinstallation.
2. Integrated Development Environment(IDE):
o PythoncomeswithanIDEcalledIDLE(IntegratedDevelopmentandLearningEnvironment)thatallows you to
write, run, and debug Python code.
o YoucanalsouseotherpopularIDEssuchasPyCharm,VSCode,andJupyterNotebook.

Python Interactive Shell


ThePythonShellisaninteractiveenvironmentwhereyoucantypePythoncommandsandseeimmediate output. This
is useful for testing code snippets or performing quick calculations.
 ToopenthePythonShell,simplytypepythoninthecommandline(afterinstallation).
 Intheshell,youcantypeexpressionslike:
python
Copycode
>>>5+3
8
BasicSyntaxinPython
1. VariablesandData Types:
o Variables:Usedtostoredata.Theydonotrequireadatatypedeclaration.
python
Copycode
x=10 #Integer
name = "John" # String
is_active = True #Boolean
o DataTypes:Pythonsupportsseveralbuilt-indatatypes:
 int:Integer(e.g.,1,2,3)
 float:Floating-pointnumber(e.g.,1.5,2.0)
 str:String(e.g.,"Hello")
 bool:Boolean(e.g.,True,False)
2. Comments:
o Single-linecommentsinPythonarewrittenusingthe#symbol:
python
Copycode
#Thisisa comment
o Multi-linecommentscanbecreatedusingtriplequotes('''or""").
3. Indentation:
Python uses indentation(whitespaceatthebeginningofaline)todefinethestructureofthecode.
Indentation replaces the use of braces{}in other languages.
python Copycode ifx>5:
print("xisgreaterthan 5")
Input and Output in Python
1. Output:
o Theprint()functionisusedtodisplayoutput:
Python Copycode
print("Hello,World!")
o Multiplevaluescanbeprintedbyseparatingthemwithcommas:
python
Copycode
print("Sumof2and3is",2+3)
2. Input:
o Theinput()functionisusedtotakeinputfromtheuser:
python
Copycode
name=input("Enteryourname:")
print("Hello, " + name)
Operators in Python
Python provides various types of operators to perform operations on variables:
1. Arithmetic Operators:
O +:Addition
o -:Subtraction
o *:Multiplication
o /:Division(returnsfloat)
o //:FloorDivision(returnsinteger)
o %:Modulus(remainder)
o **:Exponentiation
Example:
python
Copycode
a=10
b=3
print(a+b)# Output:13
print(a/b)# Output:3.3333
print(a//b)# Output:3
print(a%b)# Output:1
2. Comparison Operators:
o==:Equalto
o!=:Notequalto
o >:Greaterthan
o <:Less than
o >=:Greaterthanorequal to
o <=:Lessthanorequalto
Example:
python
Copycode
x = 5
print(x > 3) #Output:True
print(x==5) #Output: True
3. Logical Operators:
o and:ReturnsTrueifbothconditionsaretrue.
o or:ReturnsTrueifatleastoneconditionistrue.
o not:Reversesthelogicalstate.
Example:
python
Copycode
x = 5
print(x > 3 and x < 10) # Output: True
print(not(x > 3)) #Output:False

4. Assignment Operators:
o=:Assignsavaluetoa variable.
O +=:Addsand assigns.
o -=:Subtractsandassigns.
Example:
python
Copycode
x = 5
x += 2 #Equivalenttox=x+2
print(x)# Output: 7
Control Structures
1. ConditionalStatements(if,elif, else):
o Usedtoexecutecodebasedonconditions.

python Copycode age = 18


ifage>=18:
print("Youareanadult")
elifage>12:
print("Youareateenager") else:
print("Youareachild")

2. Loops:
o forloop:Usedforiteratingoverasequence(e.g.,list,tuple,string).

python
Copycode
foriinrange(5): print(i)

o whileloop:Repeatsablockofcodewhileaconditionistrue.

python
Copycode
i = 0
whilei<5:
print(i)
i += 1
Functions in Python

 Functions allow code reuse by grouping code into blocks that can be called multiple times.
python
Copycode
def greet(name):
print("Hello,"+name)

greet("Alice") #Output:Hello, Alice

 ReturnStatement:Functionscanreturnavalueusingreturn.

python
Copy code
def add(a, b):
returna+b

result = add(5, 3)
print(result) #Output:8

You might also like