0% found this document useful (0 votes)
4 views20 pages

Introduction To Python Elaborate

The document provides an introduction to Python, covering its features, syntax, and data types. It explains how to run Python, the use of identifiers, reserved keywords, variables, comments, and indentation, along with various data types such as numbers, strings, lists, tuples, sets, and dictionaries. Additionally, it discusses operators, input/output functions, and type conversion in Python.

Uploaded by

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

Introduction To Python Elaborate

The document provides an introduction to Python, covering its features, syntax, and data types. It explains how to run Python, the use of identifiers, reserved keywords, variables, comments, and indentation, along with various data types such as numbers, strings, lists, tuples, sets, and dictionaries. Additionally, it discusses operators, input/output functions, and type conversion in Python.

Uploaded by

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

Introduction to Python

Basics, Features, Syntax, and Data


Types
By Janani
Features of Python
• • Easy to learn and read.
• • Interpreted language – no need to compile.
• • Dynamically typed – no need to declare
variable types.
• • Object-oriented and functional.
• • Vast standard library.
• • Cross-platform compatibility.
• • Open-source and community-driven.
How to Run Python
• • Use Python IDEs like IDLE, PyCharm, VS
Code.
• • Run in terminal using: python filename.py
• • Use interactive mode by typing `python` in
command line.
• • Use Jupyter notebooks for notebooks-style
code execution.
Identifiers
• • Names given to variables, functions, classes,
etc.
• • Must start with a letter (A-Z, a-z) or
underscore (_).
• • Cannot start with a digit.
• • Example: my_var, _value, totalAmount.
Reserved Keywords
• • Reserved words that cannot be used as
identifiers.
• • Examples: if, else, for, while, import, def,
return, class.
• • Python has 33+ keywords.
• • Use `help("keywords")` to see them.
Variables
• • Used to store data.
• • No need to declare type – Python assigns
automatically.
• • Example:
• x = 10
• name = "Janani"
• price = 99.99
Comments in Python
• • Used to explain code.
• • Single-line: start with `#`
• • Multi-line: use triple quotes `'''` or `"""`

• Example:
• # This is a comment
• """This is a
• multi-line comment"""
Indentation in Python
• • Indentation is mandatory in Python.
• • Used to define blocks of code.
• • Standard: 4 spaces.

• Example:
• if x > 0:
• print("Positive")
Multi-Line Statements
• • Use backslash `\` to break long lines.
• • Or use parentheses `()`, brackets `[]`, or
braces `{}`.

• Example:
• total = (1 + 2 + 3 +
• 4 + 5 + 6)
Multiple Statement Group (Suite)
• • Group of statements controlled by a clause
(if, while, def).
• • Indented block after a colon `:` is the suite.

• Example:
• def greet():
• print("Hello")
• print("Welcome")
Quotes in Python
• • Python supports single (' '), double (" "), and
triple quotes (''' ''' or """ """).
• • Triple quotes allow multi-line strings.

• Examples:
• 'Hello'
• "World"
• '''Multi-line'''
Input, Output and Import
Functions
• • `input()` – get user input (as string)
• • `print()` – display output
• • `import` – include external modules

• Example:
• name = input("Enter name: ")
• print("Hello", name)
• import math
Operators in Python
• • Arithmetic: +, -, *, /, %, **, //
• • Comparison: ==, !=, >, <, >=, <=
• • Logical: and, or, not
• • Assignment: =, +=, -=, etc.
• • Bitwise and identity operators also available.
Data Types – Numbers
• • int – whole numbers (10, -5)
• • float – decimal numbers (3.14, -0.5)
• • complex – complex numbers (2 + 3j)
• Use type() to check data type.
Data Types – Strings
• • Sequence of characters inside quotes.
• • Immutable.
• • Support slicing, concatenation, repetition.

• Example:
• s = "Hello"
• print(s[0]) # H
Data Types – List
• • Ordered, mutable, allows duplicate
elements.
• • Defined with square brackets [].

• Example:
• fruits = ["apple", "banana", "cherry"]
Data Types – Tuple
• • Ordered, immutable, allows duplicate
elements.
• • Defined with parentheses ().

• Example:
• tuple1 = (1, 2, 3)
Data Types – Set
• • Unordered, mutable, no duplicates.
• • Defined with curly braces {}.

• Example:
• set1 = {1, 2, 3, 2} # {1, 2, 3}
Data Types – Dictionary
• • Key-value pairs.
• • Unordered (Python 3.6+ maintains insertion
order).

• Example:
• d = {"name": "Janani", "age": 20}
Data Type Conversion
• • Use functions like int(), float(), str(), list(),
tuple(), set(), dict().

• Examples:
• int("5") → 5
• str(5) → "5"
• list("abc") → ['a', 'b', 'c']

You might also like