This document provides an introduction to Python programming concepts including data types, operators, control flow statements, functions and modules. It discusses the basic Python data types like integers, floats, booleans, strings, lists, tuples, dictionaries and sets. It also covers Python operators like arithmetic, assignment, comparison, logical and identity operators. Additionally, it describes control flow statements like if/else and for loops. Finally, it touches on functions, modules and input/output statements in Python.
Python identifiers follow some basic rules:
1. They can include letters, numbers, and underscores.
2. They cannot start with a number.
3. Keywords like "if" cannot be used.
4. Identifiers are case-sensitive.
Of the given options, valid Python identifiers include: total1234, _abc_abc_, _p. Invalid ones include: 123total (can't start with number), java2share (contains special character), ca$h (contains special character), def (is a keyword).
Python is an interpreted, object-oriented, high-level programming language with dynamic typing and dynamic binding. Its simple, easy to learn syntax emphasizes readability and it uses significant indentation to delimit code blocks rather than curly braces or keywords. Python supports modules and packages, which encourages program modularity and code reuse. It also has a large standard library.
The document provides an overview of the Python programming language. It discusses what Python is, its history and naming, features like being dynamically typed and interpreted, popular applications like web development, machine learning, and its architecture. It also covers Python constructs like variables, data types, operators, and strings. The document compares Python to other languages and provides examples of common Python concepts.
Python is a high-level, general-purpose programming language that was created by Guido van Rossum in 1985. It is an interpreted, interactive, object-oriented language with features like dynamic typing and memory management. This document provides an overview of Python 3 and its basic syntax, data types, operators, decision making structures like if/else statements, and loops. It covers topics like variables, numbers, strings, lists, tuples, dictionaries, and type conversion between data types.
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docxfaithxdunce63732
The document discusses Python strings, functions, and methods. It provides instructions for a lab exercise on evaluating string expressions and accessing substrings using indexing and slicing. It also introduces various Python data types like strings, lists, and numbers. The document compares Python to C and Java by discussing equivalent operations like variable assignment, data types, string concatenation, slicing, and deletion statements. It categorizes Python as having more flexible data types than C and Java.
This document provides an overview of key Python concepts including numbers, strings, variables, lists, tuples, dictionaries, and sets. It defines each concept and provides examples. Numbers discusses integer, float, and complex data types. Strings covers string operations like accessing characters, concatenation, formatting and methods. Variables explains variable naming rules and scopes. Lists demonstrates accessing, modifying, and sorting list elements. Tuples describes immutable ordered collections. Dictionaries defines storing and accessing data via keys and values. Sets introduces unordered unique element collections.
Python supports several data types including numbers, strings, and lists. Numbers can be integer, float, or complex types. Strings are collections of characters that can be indexed, sliced, and manipulated using various string methods and operators. Lists are mutable sequences that can contain elements of different data types and support operations like indexing, slicing, sorting, and joining. Common list methods include append(), insert(), remove(), pop(), clear(), and sort(). Tuples are similar to lists but are immutable.
This document provides an introduction to Python programming concepts including data types, operators, control flow statements, functions and modules. It discusses the basic Python data types like integers, floats, booleans, strings, lists, tuples, dictionaries and sets. It also covers Python operators like arithmetic, assignment, comparison, logical and identity operators. Additionally, it describes control flow statements like if/else and for loops. Finally, it touches on functions, modules and input/output statements in Python.
Python identifiers follow some basic rules:
1. They can include letters, numbers, and underscores.
2. They cannot start with a number.
3. Keywords like "if" cannot be used.
4. Identifiers are case-sensitive.
Of the given options, valid Python identifiers include: total1234, _abc_abc_, _p. Invalid ones include: 123total (can't start with number), java2share (contains special character), ca$h (contains special character), def (is a keyword).
Python is an interpreted, object-oriented, high-level programming language with dynamic typing and dynamic binding. Its simple, easy to learn syntax emphasizes readability and it uses significant indentation to delimit code blocks rather than curly braces or keywords. Python supports modules and packages, which encourages program modularity and code reuse. It also has a large standard library.
The document provides an overview of the Python programming language. It discusses what Python is, its history and naming, features like being dynamically typed and interpreted, popular applications like web development, machine learning, and its architecture. It also covers Python constructs like variables, data types, operators, and strings. The document compares Python to other languages and provides examples of common Python concepts.
Python is a high-level, general-purpose programming language that was created by Guido van Rossum in 1985. It is an interpreted, interactive, object-oriented language with features like dynamic typing and memory management. This document provides an overview of Python 3 and its basic syntax, data types, operators, decision making structures like if/else statements, and loops. It covers topics like variables, numbers, strings, lists, tuples, dictionaries, and type conversion between data types.
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docxfaithxdunce63732
The document discusses Python strings, functions, and methods. It provides instructions for a lab exercise on evaluating string expressions and accessing substrings using indexing and slicing. It also introduces various Python data types like strings, lists, and numbers. The document compares Python to C and Java by discussing equivalent operations like variable assignment, data types, string concatenation, slicing, and deletion statements. It categorizes Python as having more flexible data types than C and Java.
This document provides an overview of key Python concepts including numbers, strings, variables, lists, tuples, dictionaries, and sets. It defines each concept and provides examples. Numbers discusses integer, float, and complex data types. Strings covers string operations like accessing characters, concatenation, formatting and methods. Variables explains variable naming rules and scopes. Lists demonstrates accessing, modifying, and sorting list elements. Tuples describes immutable ordered collections. Dictionaries defines storing and accessing data via keys and values. Sets introduces unordered unique element collections.
Python supports several data types including numbers, strings, and lists. Numbers can be integer, float, or complex types. Strings are collections of characters that can be indexed, sliced, and manipulated using various string methods and operators. Lists are mutable sequences that can contain elements of different data types and support operations like indexing, slicing, sorting, and joining. Common list methods include append(), insert(), remove(), pop(), clear(), and sort(). Tuples are similar to lists but are immutable.
Python supports several numeric and non-numeric data types including integers, floats, complex numbers, strings, lists, and tuples. Numbers can be integers, floats, or complex, and support common operations. Strings are immutable sequences of characters that can be indexed, sliced, formatted, and concatenated. Lists are mutable sequences that can contain mixed data types, and support common operations like indexing, slicing, sorting, and joining. Tuples are similar to lists but are immutable.
Python (Data Analysis) cleaning and visualizeIruolagbePius
This document provides an overview of Python programming language. It discusses Python features, uses, variables, data types, operators, decision making statements, and loops. Specifically, it covers:
- Python features like being easy to learn and read, having an interactive mode, and being portable.
- Python variables, naming rules, and basic data types like numbers, strings, booleans.
- Operators for arithmetic, comparison, assignment, and logic.
- Conditional statements like if, elif, else for decision making.
- Looping structures like while and for loops, with examples of using break, continue, else, range().
- How to write comments, take user input, and
A pointer is a variable that stores the memory address of another variable. Pointers allow accessing and modifying the data stored at the referenced memory location. Pointers can be declared by specifying the data type followed by an asterisk, and are initialized by assigning the address of a variable to the pointer variable. Pointer variables can be used in expressions and arithmetic and can be passed to functions to modify the referenced data. Arrays can also be accessed and traversed using pointers by treating the array name as a pointer to its first element. Pointers to functions allow functions to be passed as arguments and enables polymorphism.
Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language.
Make use of the PPT to have a better understanding of Python.
This document provides an overview of Python data types including numeric, string, sequence, mapping, boolean, and set data types. It describes the main classes for each data type such as int, float, complex for numeric types, str for strings, list, tuple, range for sequences, dict for mappings, bool for booleans, and set, frozenset for sets. It includes examples of defining variables of each data type and using functions like type() and isinstance() to check the data type. It also summarizes key aspects of each data type like how they can be indexed, sliced, concatenated, and repeated.
Basic concept of Python.pptx includes design tool, identifier, variables.supriyasarkar38
This document discusses Python programming concepts including data types, variables, operators, and functions. It provides examples of Python syntax for writing and executing code as well as built-in data types like strings, integers, and lists. Key concepts covered include variables, data type casting, comments, arithmetic and comparison operators, and functions.
The document discusses Python programming language. It provides an overview of what Python is, what it can be used for, and why it is a popular language. Specifically, it notes that Python was created by Guido van Rossum and released in 1991. It is used for web development, software development, mathematics, and system scripting. The document then covers Python syntax, basic data types, operators, decision making and control flow statements like if/else and loops.
This document provides an overview of the basics of the Python programming language. It discusses Python's history and features, data types like numbers, strings, lists, tuples and dictionaries. It also covers Python concepts like variables, operators, control flow statements and functions. Specific topics covered include Python interpreters, comments, variables and scopes, data structures, conditional statements like if/else, and exceptions handling.
This document provides an overview of the Python programming language in 3 paragraphs. It discusses that Python is a high-level, interpreted, interactive and object-oriented scripting language. It was created by Guido van Rossum in the late 1980s and derived from languages like C and C++. The document then covers some key features of Python, including that it is easy to learn and read, portable, extensible and supports object-oriented programming. It provides examples of Python's basic syntax including indentation, variables, data types, operators and more.
This document discusses Python lists. It defines lists as ordered collections of elements that can contain items of different data types. Lists are mutable and can be modified by adding, removing, or changing elements. Some key points made include:
- Lists are created using square brackets [] and elements are separated by commas
- Individual elements can be accessed by their integer index
- Common list methods include len() to get length, max() and min() to find extremes, and append() to add an element
- Operators like + for concatenation and [:] for slicing can be used to modify and extract subsets of list elements.
Python Programming for basic beginners.pptxmohitesoham12
The document provides an overview of Python programming concepts including data types, variables, operators, and collections like lists and tuples. It defines Python as a general purpose programming language created in 1991 that can be used for desktop, web, machine learning, and data science apps. Key data types covered include numbers, strings, lists, and tuples. Operators for arithmetic, comparison, logical, membership, and identity are also summarized. Various list and tuple methods for accessing, modifying, sorting, and joining their items are demonstrated through examples.
The document discusses lists in Python. It defines lists as collections of values separated by commas and enclosed in square brackets. It provides examples of creating lists and performing common operations like concatenation, repetition, slicing, membership testing, indexing, updating/changing elements, and built-in functions/methods like len(), min(), max(), sort(), and reverse(). The document also covers iterating through lists using for loops and deleting elements using the del statement.
This document provides a cheat sheet for Python basics. It begins with an introduction to Python and its advantages. It then covers key Python data types like strings, integers, floats, lists, tuples, and dictionaries. It explains how to define variables, functions, conditional statements, and loops. The document also demonstrates built-in functions, methods for manipulating common data structures, and other Python programming concepts in a concise and easy to understand manner.
This document provides an introduction and overview of the Python programming language course CSE 120 handled by G.Gandhi Jaba Kumar. It discusses that Python is an interpreted, object-oriented, and interactive programming language used for web development, software development, mathematics, and system scripting. The document then covers Python syntax including indentation, comments, keywords, variables, data types, operators, and basic programming concepts like conditionals and loops. It provides examples to illustrate Python code and best practices.
A review of the growth of the Israel Genealogy Research Association Database Collection for the last 12 months. Our collection is now passed the 3 million mark and still growing. See which archives have contributed the most. See the different types of records we have, and which years have had records added. You can also see what we have for the future.
Python supports several numeric and non-numeric data types including integers, floats, complex numbers, strings, lists, and tuples. Numbers can be integers, floats, or complex, and support common operations. Strings are immutable sequences of characters that can be indexed, sliced, formatted, and concatenated. Lists are mutable sequences that can contain mixed data types, and support common operations like indexing, slicing, sorting, and joining. Tuples are similar to lists but are immutable.
Python (Data Analysis) cleaning and visualizeIruolagbePius
This document provides an overview of Python programming language. It discusses Python features, uses, variables, data types, operators, decision making statements, and loops. Specifically, it covers:
- Python features like being easy to learn and read, having an interactive mode, and being portable.
- Python variables, naming rules, and basic data types like numbers, strings, booleans.
- Operators for arithmetic, comparison, assignment, and logic.
- Conditional statements like if, elif, else for decision making.
- Looping structures like while and for loops, with examples of using break, continue, else, range().
- How to write comments, take user input, and
A pointer is a variable that stores the memory address of another variable. Pointers allow accessing and modifying the data stored at the referenced memory location. Pointers can be declared by specifying the data type followed by an asterisk, and are initialized by assigning the address of a variable to the pointer variable. Pointer variables can be used in expressions and arithmetic and can be passed to functions to modify the referenced data. Arrays can also be accessed and traversed using pointers by treating the array name as a pointer to its first element. Pointers to functions allow functions to be passed as arguments and enables polymorphism.
Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language.
Make use of the PPT to have a better understanding of Python.
This document provides an overview of Python data types including numeric, string, sequence, mapping, boolean, and set data types. It describes the main classes for each data type such as int, float, complex for numeric types, str for strings, list, tuple, range for sequences, dict for mappings, bool for booleans, and set, frozenset for sets. It includes examples of defining variables of each data type and using functions like type() and isinstance() to check the data type. It also summarizes key aspects of each data type like how they can be indexed, sliced, concatenated, and repeated.
Basic concept of Python.pptx includes design tool, identifier, variables.supriyasarkar38
This document discusses Python programming concepts including data types, variables, operators, and functions. It provides examples of Python syntax for writing and executing code as well as built-in data types like strings, integers, and lists. Key concepts covered include variables, data type casting, comments, arithmetic and comparison operators, and functions.
The document discusses Python programming language. It provides an overview of what Python is, what it can be used for, and why it is a popular language. Specifically, it notes that Python was created by Guido van Rossum and released in 1991. It is used for web development, software development, mathematics, and system scripting. The document then covers Python syntax, basic data types, operators, decision making and control flow statements like if/else and loops.
This document provides an overview of the basics of the Python programming language. It discusses Python's history and features, data types like numbers, strings, lists, tuples and dictionaries. It also covers Python concepts like variables, operators, control flow statements and functions. Specific topics covered include Python interpreters, comments, variables and scopes, data structures, conditional statements like if/else, and exceptions handling.
This document provides an overview of the Python programming language in 3 paragraphs. It discusses that Python is a high-level, interpreted, interactive and object-oriented scripting language. It was created by Guido van Rossum in the late 1980s and derived from languages like C and C++. The document then covers some key features of Python, including that it is easy to learn and read, portable, extensible and supports object-oriented programming. It provides examples of Python's basic syntax including indentation, variables, data types, operators and more.
This document discusses Python lists. It defines lists as ordered collections of elements that can contain items of different data types. Lists are mutable and can be modified by adding, removing, or changing elements. Some key points made include:
- Lists are created using square brackets [] and elements are separated by commas
- Individual elements can be accessed by their integer index
- Common list methods include len() to get length, max() and min() to find extremes, and append() to add an element
- Operators like + for concatenation and [:] for slicing can be used to modify and extract subsets of list elements.
Python Programming for basic beginners.pptxmohitesoham12
The document provides an overview of Python programming concepts including data types, variables, operators, and collections like lists and tuples. It defines Python as a general purpose programming language created in 1991 that can be used for desktop, web, machine learning, and data science apps. Key data types covered include numbers, strings, lists, and tuples. Operators for arithmetic, comparison, logical, membership, and identity are also summarized. Various list and tuple methods for accessing, modifying, sorting, and joining their items are demonstrated through examples.
The document discusses lists in Python. It defines lists as collections of values separated by commas and enclosed in square brackets. It provides examples of creating lists and performing common operations like concatenation, repetition, slicing, membership testing, indexing, updating/changing elements, and built-in functions/methods like len(), min(), max(), sort(), and reverse(). The document also covers iterating through lists using for loops and deleting elements using the del statement.
This document provides a cheat sheet for Python basics. It begins with an introduction to Python and its advantages. It then covers key Python data types like strings, integers, floats, lists, tuples, and dictionaries. It explains how to define variables, functions, conditional statements, and loops. The document also demonstrates built-in functions, methods for manipulating common data structures, and other Python programming concepts in a concise and easy to understand manner.
This document provides an introduction and overview of the Python programming language course CSE 120 handled by G.Gandhi Jaba Kumar. It discusses that Python is an interpreted, object-oriented, and interactive programming language used for web development, software development, mathematics, and system scripting. The document then covers Python syntax including indentation, comments, keywords, variables, data types, operators, and basic programming concepts like conditionals and loops. It provides examples to illustrate Python code and best practices.
Similaire à 1691912901477_Python_Basics and list,tuple,string.pptx (20)
A review of the growth of the Israel Genealogy Research Association Database Collection for the last 12 months. Our collection is now passed the 3 million mark and still growing. See which archives have contributed the most. See the different types of records we have, and which years have had records added. You can also see what we have for the future.
Leveraging Generative AI to Drive Nonprofit InnovationTechSoup
In this webinar, participants learned how to utilize Generative AI to streamline operations and elevate member engagement. Amazon Web Service experts provided a customer specific use cases and dived into low/no-code tools that are quick and easy to deploy through Amazon Web Service (AWS.)
This presentation includes basic of PCOS their pathology and treatment and also Ayurveda correlation of PCOS and Ayurvedic line of treatment mentioned in classics.
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxEduSkills OECD
Iván Bornacelly, Policy Analyst at the OECD Centre for Skills, OECD, presents at the webinar 'Tackling job market gaps with a skills-first approach' on 12 June 2024
বাংলাদেশের অর্থনৈতিক সমীক্ষা ২০২৪ [Bangladesh Economic Review 2024 Bangla.pdf] কম্পিউটার , ট্যাব ও স্মার্ট ফোন ভার্সন সহ সম্পূর্ণ বাংলা ই-বুক বা pdf বই " সুচিপত্র ...বুকমার্ক মেনু 🔖 ও হাইপার লিংক মেনু 📝👆 যুক্ত ..
আমাদের সবার জন্য খুব খুব গুরুত্বপূর্ণ একটি বই ..বিসিএস, ব্যাংক, ইউনিভার্সিটি ভর্তি ও যে কোন প্রতিযোগিতা মূলক পরীক্ষার জন্য এর খুব ইম্পরট্যান্ট একটি বিষয় ...তাছাড়া বাংলাদেশের সাম্প্রতিক যে কোন ডাটা বা তথ্য এই বইতে পাবেন ...
তাই একজন নাগরিক হিসাবে এই তথ্য গুলো আপনার জানা প্রয়োজন ...।
বিসিএস ও ব্যাংক এর লিখিত পরীক্ষা ...+এছাড়া মাধ্যমিক ও উচ্চমাধ্যমিকের স্টুডেন্টদের জন্য অনেক কাজে আসবে ...
Chapter wise All Notes of First year Basic Civil Engineering.pptxDenish Jangid
Chapter wise All Notes of First year Basic Civil Engineering
Syllabus
Chapter-1
Introduction to objective, scope and outcome the subject
Chapter 2
Introduction: Scope and Specialization of Civil Engineering, Role of civil Engineer in Society, Impact of infrastructural development on economy of country.
Chapter 3
Surveying: Object Principles & Types of Surveying; Site Plans, Plans & Maps; Scales & Unit of different Measurements.
Linear Measurements: Instruments used. Linear Measurement by Tape, Ranging out Survey Lines and overcoming Obstructions; Measurements on sloping ground; Tape corrections, conventional symbols. Angular Measurements: Instruments used; Introduction to Compass Surveying, Bearings and Longitude & Latitude of a Line, Introduction to total station.
Levelling: Instrument used Object of levelling, Methods of levelling in brief, and Contour maps.
Chapter 4
Buildings: Selection of site for Buildings, Layout of Building Plan, Types of buildings, Plinth area, carpet area, floor space index, Introduction to building byelaws, concept of sun light & ventilation. Components of Buildings & their functions, Basic concept of R.C.C., Introduction to types of foundation
Chapter 5
Transportation: Introduction to Transportation Engineering; Traffic and Road Safety: Types and Characteristics of Various Modes of Transportation; Various Road Traffic Signs, Causes of Accidents and Road Safety Measures.
Chapter 6
Environmental Engineering: Environmental Pollution, Environmental Acts and Regulations, Functional Concepts of Ecology, Basics of Species, Biodiversity, Ecosystem, Hydrological Cycle; Chemical Cycles: Carbon, Nitrogen & Phosphorus; Energy Flow in Ecosystems.
Water Pollution: Water Quality standards, Introduction to Treatment & Disposal of Waste Water. Reuse and Saving of Water, Rain Water Harvesting. Solid Waste Management: Classification of Solid Waste, Collection, Transportation and Disposal of Solid. Recycling of Solid Waste: Energy Recovery, Sanitary Landfill, On-Site Sanitation. Air & Noise Pollution: Primary and Secondary air pollutants, Harmful effects of Air Pollution, Control of Air Pollution. . Noise Pollution Harmful Effects of noise pollution, control of noise pollution, Global warming & Climate Change, Ozone depletion, Greenhouse effect
Text Books:
1. Palancharmy, Basic Civil Engineering, McGraw Hill publishers.
2. Satheesh Gopi, Basic Civil Engineering, Pearson Publishers.
3. Ketki Rangwala Dalal, Essentials of Civil Engineering, Charotar Publishing House.
4. BCP, Surveying volume 1
Main Java[All of the Base Concepts}.docxadhitya5119
This is part 1 of my Java Learning Journey. This Contains Custom methods, classes, constructors, packages, multithreading , try- catch block, finally block and more.
Reimagining Your Library Space: How to Increase the Vibes in Your Library No ...Diana Rendina
Librarians are leading the way in creating future-ready citizens – now we need to update our spaces to match. In this session, attendees will get inspiration for transforming their library spaces. You’ll learn how to survey students and patrons, create a focus group, and use design thinking to brainstorm ideas for your space. We’ll discuss budget friendly ways to change your space as well as how to find funding. No matter where you’re at, you’ll find ideas for reimagining your space in this session.
How to Setup Warehouse & Location in Odoo 17 InventoryCeline George
In this slide, we'll explore how to set up warehouses and locations in Odoo 17 Inventory. This will help us manage our stock effectively, track inventory levels, and streamline warehouse operations.
This presentation was provided by Steph Pollock of The American Psychological Association’s Journals Program, and Damita Snow, of The American Society of Civil Engineers (ASCE), for the initial session of NISO's 2024 Training Series "DEIA in the Scholarly Landscape." Session One: 'Setting Expectations: a DEIA Primer,' was held June 6, 2024.
2. Content
• Comments in Python
• Variable Declaration in Python
• Data Types in Python
• Type Conversion in Python
• Operators in Python
3. Comments in Python
• In general, Comments are used in a programming language to
describe the program or to hide the some part of code from
the interpreter.
• Comments in Python can be used to explain any program
code. It can also be used to hide the code as well.
• Comment is not a part of the program, but it enhances the
interactivity of the program and makes the program readable.
Python supports two types of comments:
• Single Line Comment
• Multi Line Comment
4. Comments in Python Cont..
Single Line Comment:
In case user wants to specify a single line comment, then comment must start
with ‘#’
Example:
# This is single line comment
print "Hello Python"
Output:
Hello Python
Multi Line Comment:
Multi lined comment can be given inside triple quotes.
Example:
'''This is
Multiline
Comment'''
print "Hello Python"
Output:
Hello Python
5. Variable Declaration in Python
• A variable is a named memory location in which we can store
values for the particular program.
• In other words, Variable is a name which is used to refer
memory location. Variable also known as identifier and used
to hold value.
• In Python, We don't need to declare explicitly variable in
Python. When we assign any value to the variable that
variable is declared automatically.
• In Python, We don't need to specify the type of variable
because Python is a loosely typed language.
6. Variable Declaration in Python Cont..
• In loosely typed language no need to specify the type of
variable because the variable automatically changes it's data
type based on assigned value.
Rules for naming variable:
• Variable names can be a group of both letters and digits, but
they have to begin with a letter or an underscore.
• It is recommended to use lowercase letters for variable name.
‘SUM’ and ‘sum’ both are two different variables.
Example: Vardemo.py
a=10 #integer
b=“python" #string
c=12.5 #float
print(a)
print(b)
print(c)
output:
$python3 Vardemo.py
10
python
12.5
7. Variable Declaration in Python Cont..
• Python allows us to assign a value to multiple variables and
multiple values to multiple variables in a single statement
which is also known as multiple assignment.
• Assign single value to multiple variables :
• Assign multiple values to multiple variables :
Example: Vardemo1.py
x=y=z=50
print x
print y
print z
output:
$python3 Vardemo1.py
50
50
50
Example: Vardemo2.py
a,b,c=5,10,15
print a
print b
print c
output:
$python3 Vardemo2.py
5
10
15
8. Data Types in Python
• In general, Data Types specifies what type of data will be
stored in variables. Variables can hold values of different data
types.
• Python is a dynamically typed or loosely typed language,
hence we need not define the type of the variable while
declaring it.
• The interpreter implicitly binds the value with its type.
• Python provides us the type () function which enables us to
check the type of the variable.
9. Data Types in Python Cont..
• Python provides following standard data types, those are
Numbers
String
Numbers:
• Number stores numeric values. Python creates Number type
variable when a number is assigned to a variable.
There are three numeric types in Python:
1. int
2. float
3. Complex
10. Data Types in Python Cont..
2. float:
Float or "floating point number" is a
number, positive or negative, containing
decimals.
Example:
X=1.0
Y=12.3
Z=-13.4
3. complex:
Complex numbers are written with a "j" as
the imaginary part.
Example:
A=2+5j
B=-3+4j
C=-6j
1. int:
Int, or integer, is a whole number, positive or
negative, without decimals, of unlimited
length.
Example:
a=10
b=-12
c=123456789
11. Data Types in Python Cont..
String:
• The string can be defined as the sequence of characters
represented in the quotation marks. In python, we can use
single, double, or triple quotes to define a string.
• In the case of string handling, the operator + is used to
concatenate two strings as the operation "hello"+"
python" returns "hello python".
Example:
S1=‘Welcome’ #using single quotes
S2=“To” #using double quotes
S3=‘’’Python’’’ #using triple quotes
12. Data Types in Python Cont..
Example: “datatypesdemo.py”
a=10
b=“Python"
c = 10.5
d=2.14j
print("Data type of Variable a :",type(a))
print("Data type of Variable b :",type(b))
print("Data type of Variable c :",type(c))
print("Data type of Variable d :",type(d))
Output:
python3 datatypesdemo.py
Datatype of Variable a : <class ‘int’>
Datatype of Variable b : <class ‘str’>
Datatype of Variable c : <class ‘float’>
Datatype of Variable d : <class ‘complex’>
13. Type Conversion in Python
• Python provides Explicit type conversion functions to directly
convert one data type to another. It is also called as Type Casting in
Python
• Python supports following functions
1. int () : This function converts any data type to integer.
2. float() : This function is used to convert any data type to a floating point
number.
3. str() : This function is used to convert any data type to a string.
Example:“Typeconversiondemo.py”
x = int(2.8)
y = int("3")
z = float(2)
s = str(10)
print(x);print(y)
print(z); print(s)
Output:
python3 typeconversiondemo.py
2
3
2
10
16. List in Python
• In python, a list can be defined as a collection of values or
items.
• The items in the list are separated with the comma (,) and
enclosed with the square brackets [ ].
Syntax:
listname = [ value1, value2, value3,…. ]
Example: “listdemo.py”
L1 = []
L2 = [123,"python", 3.7]
L3 = [1, 2, 3, 4, 5, 6]
L4 = ["C","Java","Python"]
print(L1)
print(L2)
print(L3)
print(L4)
Output:
python listdemo.py
[]
[123, 'python', 3.7]
[1, 2, 3, 4, 5, 6]
['C','Java','Python']
18. List Indexing in Python
• Like string sequence, the indexing of the python lists starts from
0, i.e. the first element of the list is stored at the 0th index, the
second element of the list is stored at the 1st index, and so on.
• The elements of the list can be accessed by using the slice
operator [].
Example:
mylist=[‘banana’,’apple’,’mango’,’tomato’,’berry’]
• mylist[0]=”banana” mylist[1:3]=[”apple”,”mango”]
• mylist[2]=”mango”
19. List Indexing in Python cont…
• Unlike other languages, python provides us the flexibility to use
the negative indexing also. The negative indices are counted
from the right.
• The last element (right most) of the list has the index -1, its
adjacent left element is present at the index -2 and so on until
the left most element is encountered.
Example: mylist=[‘banana’,’apple’,’mango’,’tomato’,’berry’]
• mylist[-1]=”berry” mylist[-4:-2]=[“apple”,mango”]
• mylist[-3]=”mango”
21. List Operators in Python
+
It is known as concatenation operator used to concatenate two
lists.
*
It is known as repetition operator. It concatenates the multiple
copies of the same list.
[]
It is known as slice operator. It is used to access the list item
from list.
[:]
It is known as range slice operator. It is used to access the range
of list items from list.
in
It is known as membership operator. It returns if a particular
item is present in the specified list.
not in
It is also a membership operator and It returns true if a
particular list item is not present in the list.
22. List Operators in Python cont…
Example: “listopdemo.py”
num=[1,2,3,4,5]
lang=['python','c','java','php']
print(num + lang) #concatenates two lists
print(num * 2) #concatenates same list 2 times
print(lang[2]) # prints 2nd index value
print(lang[1:4]) #prints values from 1st to 3rd index.
print('cpp' in lang) # prints False
print(6 not in num) # prints True
Output: python listopdemo.py
[1, 2, 3, 4, 5, 'python', 'c', 'java', 'php']
[1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
java
['c', 'java', 'php']
False
True
23. How to update or change elements to a list?
• Python allows us to modify the list items by using the slice and
assignment operator.
• We can use assignment operator ( = ) to change an item or a
range of items.
Example: “listopdemo1.py”
num=[1,2,3,4,5]
print(num)
num[2]=30
print(num)
num[1:3]=[25,36]
print(num)
num[4]="Python"
print(num)
Output:
python listopdemo1.py
[1, 2, 3, 4, 5]
[1, 2, 30, 4, 5]
[1, 25, 36, 4, 5]
[1, 25, 36, 4, 'Python']
24. How to delete or remove elements from a list?
• Python allows us to delete one or more items in a list by using
the del keyword.
Example: “listopdemo2.py”
num = [1,2,3,4,5]
print(num)
del num[1]
print(num)
del num[1:3]
print(num)
Output:
python listopdemo2.py
[1, 2, 3, 4, 5]
[1, 3, 4, 5]
[1, 5]
26. List Functions & Methods in Python
• Python provides various in-built functions and methods which
can be used with list. Those are
☞ len():
• In Python, len() function is used to find the length of list,i.e it
returns the number of items in the list..
Syntax: len(list)
• len()
• max()
• min()
• sum()
• list()
Example: listlendemo.py
num=[1,2,3,4,5,6]
print("length of list :",len(num))
Output:
python listlendemo.py
length of list : 6
• sorted()
• append()
• remove()
• sort()
• reverse()
• count()
• index()
• insert()
• pop()
• clear()
27. List Functions & Methods in Python Cont..
☞ max ():
• In Python, max() function is used to find maximum value in the list.
Syntax: max(list)
Example: listmaxdemo.py
list1=[1,2,3,4,5,6]
list2=['java','c','python','cpp']
print("Max of list1 :",max(list1))
print("Max of list2 :",max(list2))
Output:
python listmaxdemo.py
Max of list1 : 6
Max of list2 : python
28. List Functions & Methods in Python Cont..
☞ min ():
• In Python, min() function is used to find minimum value in the list.
Syntax: min(list)
Example: listmindemo.py
list1=[1,2,3,4,5,6]
list2=['java','c','python','cpp']
print("Min of list1 :",min(list1))
print("Min of list2 :",min(list2))
Output:
python listmindemo.py
Min of list1 : 1
Min of list2 : c
29. List Functions & Methods in Python Cont..
☞ sum ():
• In python, sum() function returns sum of all values in the list. List
values must in number type.
Syntax: sum(list)
Example: listsumdemo.py
list1=[1,2,3,4,5,6]
print("Sum of list items :",sum(list1))
Output:
python listsumdemo.py
Sum of list items : 21
30. List Functions & Methods in Python Cont..
☞ list ():
• In python, list() is used to convert given sequence (string or tuple)
into list.
Syntax: list(sequence)
Example: listdemo.py
str="python"
list1=list(str)
print(list1)
Output:
python listdemo.py
['p', 'y', 't', 'h', 'o', 'n']
31. List Functions & Methods in Python Cont..
☞ sorted ():
• In python, sorted() function is used to sort all items of list in an
ascending order.
Syntax: sorted(list)
Example: sorteddemo.py
num=[1,3,2,4,6,5]
lang=['java','c','python','cpp']
print(sorted(num))
print(sorted(lang))
Output:
python sorteddemo.py
[1, 2, 3, 4, 5, 6]
['c', 'cpp', 'java', 'python']
32. List Functions & Methods in Python Cont..
☞ append ():
• In python, append() method adds an item to the end of the list.
Syntax: list.append(item)
where item may be number, string, list and etc.
Example: appenddemo.py
num=[1,2,3,4,5]
lang=['python','java']
num.append(6)
print(num)
lang.append("cpp")
print(lang)
Output:
python appenddemo.py
[1, 2, 3, 4, 5, 6]
['python', 'java', 'cpp']
33. List Functions & Methods in Python Cont..
☞ remove ():
• In python, remove() method removes item from the list. It removes
first occurrence of item if list contains duplicate items. It throws an
error if the item is not present in the list.
Syntax: list.remove(item)
Example: removedemo.py
list1=[1,2,3,4,5]
list2=['A','B','C','B','D']
list1.remove(2)
print(list1)
list2.remove("B")
print(list2)
list2.remove("E")
print(list2)
Output:
python removedemo.py
[1, 3, 4, 5]
['A', 'C', 'B', 'D']
ValueError: x not in list
34. List Functions & Methods in Python Cont..
☞ sort ():
• In python, sort() method sorts the list elements into descending or
ascending order. By default, list sorts the elements into ascending
order. It takes an optional parameter 'reverse' which sorts the list
into descending order.
Syntax: list.sort([reverse=true])
Example: sortdemo.py
list1=[6,8,2,4,10]
list1.sort()
print("n After Sorting:n")
print(list1)
print("Descending Order:n")
list1.sort(reverse=True)
print(list1)
Output:
python sortdemo.py
After Sorting:
[2, 4, 6, 8 , 10]
Descending Order:
[10, 8, 6, 4 , 2]
35. List Functions & Methods in Python Cont..
☞ reverse ():
• In python, reverse() method reverses elements of the list. i.e. the
last index value of the list will be present at 0th index.
Syntax: list.reverse()
Example: reversedemo.py
list1=[6,8,2,4,10]
list1.reverse()
print("n After reverse:n")
print(list1)
Output:
python reversedemo.py
After reverse:
[10, 4, 2, 8 , 6]
36. List Functions & Methods in Python Cont..
☞ count():
• In python, count() method returns the number of times an element
appears in the list. If the element is not present in the list, it
returns 0.
Syntax: list.count(item)
Example: countdemo.py
num=[1,2,3,4,3,2,2,1,4,5,8]
cnt=num.count(2)
print("Count of 2 is:",cnt)
cnt=num.count(10)
print("Count of 10 is:",cnt) Output:
python countdemo.py
Count of 2 is: 3
Count of 10 is: 0
37. List Functions & Methods in Python Cont..
☞ index():
• In python, index () method returns index of the passed element. If
the element is not present, it raises a ValueError.
• If list contains duplicate elements, it returns index of first
occurred element.
• This method takes two more optional parameters start and end
which are used to search index within a limit.
Syntax: list. index(item [, start[, end]])
Example: indexdemo.py
list1=['p','y','t','o','n','p']
print(list1.index('t'))
Print(list1.index('p'))
Print(list1.index('p',3,10))
Print(list1.index('z')) )
Output:
python indexdemo.py
2
0
5
Value Error
38. List Functions & Methods in Python Cont..
☞ insert():
• In python, insert() method inserts the element at the specified
index in the list. The first argument is the index of the element
before which to insert the element.
Syntax: list.insert(index,item)
Example: insertdemo.py
num=[10,20,30,40,50]
num.insert(4,60)
print(num)
num.insert(7,70)
print(num)
Output:
python insertdemo.py
[10, 20, 30, 40, 60, 50]
[10, 20, 30, 40, 60, 50, 70]
39. List Functions & Methods in Python Cont..
☞ pop():
• In python, pop() element removes an element present at specified
index from the list.
Syntax: list.pop(index)
Example: popdemo.py
num=[10,20,30,40,50]
num.pop()
print(num)
num.pop(2)
print(num)
num.pop(7)
print(num)
Output:
python popdemo.py
[10, 20, 30, 40]
[10, 20, 40]
IndexError: Out of range
40. List Functions & Methods in Python Cont..
☞ clear():
• In python, clear() method removes all the elements from the list.
It clears the list completely and returns nothing.
Syntax: list.clear()
Example: cleardemo.py
num=[10,20,30,40,50]
num.clear()
print(num)
Output:
python cleardemo.py
[ ]
43. Tuple in Python
• In python, a tuple is a sequence of immutable elements or items.
• Tuple is similar to list since the items stored in the list can be
changed whereas the tuple is immutable and the items stored in
the tuple cannot be changed.
• A tuple can be written as the collection of comma-separated
values enclosed with the small brackets or parantheses ( ).
Syntax: var = ( value1, value2, value3,…. )
Example: “tupledemo.py”
t1 = ()
t2 = (123,"python", 3.7)
t3 = (1, 2, 3, 4, 5, 6)
t4 = ("C",)
print(t1)
print(t2)
print(t3)
print(t4)
Output:
python tupledemo.py
()
(123, 'python', 3.7)
(1, 2, 3, 4, 5, 6)
('C',)
45. Tuple Indexing in Python
• Like list sequence, the indexing of the python tuple starts from
0, i.e. the first element of the tuple is stored at the 0th index,
the second element of the tuple is stored at the 1st index, and
so on.
• The elements of the tuple can be accessed by using the slice
operator [].
Example:
mytuple=(‘banana’,’apple’,’mango’,’tomato’,’berry’)
• mytuple[0]=”banana” mytuple[1:3]=[”apple”,”mango”]
• mytuple[2]=”mango”
46. Tuple Indexing in Python cont…
• Unlike other languages, python provides us the flexibility to use
the negative indexing also. The negative indices are counted
from the right.
• The last element (right most) of the tuple has the index -1, its
adjacent left element is present at the index -2 and so on until
the left most element is encountered.
Example: mytuple=[‘banana’,’apple’,’mango’,’tomato’,’berry’]
• mytuple[-1]=”berry” mytuple[-4:-2]=[“apple”,mango”]
• mytuple[-3]=”mango”
48. Tuple Operators in Python
+
It is known as concatenation operator used to concatenate two
tuples.
*
It is known as repetition operator. It concatenates the multiple
copies of the same tuple.
[]
It is known as slice operator. It is used to access the item from
tuple.
[:]
It is known as range slice operator. It is used to access the range
of items from tuple.
in
It is known as membership operator. It returns if a particular
item is present in the specified tuple.
not in
It is also a membership operator and It returns true if a
particular item is not present in the tuple.
49. Tuple Operators in Python cont…
Example: “tupleopdemo.py”
num=(1,2,3,4,5)
lang=('python','c','java','php')
print(num + lang) #concatenates two tuples
print(num * 2) #concatenates same tuple 2 times
print(lang[2]) # prints 2nd index value
print(lang[1:4]) #prints values from 1st to 3rd index.
print('cpp' in lang) # prints False
print(6 not in num) # prints True
Output: python tupleopdemo.py
(1, 2, 3, 4, 5, 'python', 'c', 'java', 'php')
(1, 2, 3, 4, 5, 1, 2, 3, 4, 5)
java
('c', 'java', 'php')
False
True
50. How to add or remove elements from a tuple?
• Unlike lists, the tuple items cannot be updated or deleted as
tuples are immutable.
• To delete an entire tuple, we can use the del keyword with the
tuple name.
Example: “tupledemo1.py”
tup=('python','c','java','php')
tup[3]="html"
print(tup)
del tup[3]
print(tup)
del tup
Output:
python tupledemo1.py
'tuple' object does not
support item assignment
'tuple' object doesn't
support item deletion
52. Tuples Functions & Methods in Python
• Python provides various in-built functions and methods which
can be used with tuples. Those are
☞ len():
• In Python, len() function is used to find the length of tuple,i.e it
returns the number of items in the tuple.
Syntax: len(tuple)
• len()
• max()
• min()
• sum()
Example: lendemo.py
num=(1,2,3,4,5,6)
print("length of tuple :",len(num))
Output:
python lendemo.py
length of tuple : 6
• tuple()
•sorted()
• count()
• index()
53. Tuple Functions & Methods in Python Cont..
☞ max ():
• In Python, max() function is used to find maximum value in the
tuple.
Syntax: max(tuple)
Example: maxdemo.py
t1=(1,2,3,4,5,6)
t2=('java','c','python','cpp')
print("Max of Tuple t1 :",max(t1))
print("Max of Tuple t2 :",max(t2))
Output:
python maxdemo.py
Max of Tuple t1 : 6
Max of Tuple t2 : python
54. Tuple Functions & Methods in Python Cont..
☞ min ():
• In Python, min() is used to find minimum value in the tuple.
Syntax: min(tuple)
Example: mindemo.py
t1=(1,2,3,4,5,6)
t2=('java','c','python','cpp')
print("Min of Tuple t1 :",min(t1))
print("Min of Tuple t2 :",min(t2))
Output:
python mindemo.py
Min of Tuple t1 : 1
Min of Tuple t2 : c
55. Tuple Functions & Methods in Python Cont..
☞ sum ():
• In python, sum() function returns sum of all values in the tuple. The
tuple values must in number type.
Syntax: sum(tuple)
Example: sumdemo.py
t1=(1,2,3,4,5,6)
print("Sum of tuple items :",sum(t1))
Output:
python sumdemo.py
Sum of tuple items : 21
56. Tuple Functions & Methods in Python Cont..
☞ tuple ():
• In python, tuple() is used to convert given sequence (string or list)
into tuple.
Syntax: tuple(sequence)
Example: tupledemo.py
str="python"
t1=tuple(str)
print(t1)
num=[1,2,3,4,5,6]
t2=tuple(num)
print(t2)
Output:
python tupledemo.py
('p', 'y', 't', 'h', 'o', 'n‘)
(1, 2, 3, 4, 5, 6)
57. Tuple Functions & Methods in Python Cont..
☞ sorted ():
• In python, sorted() function is used to sort all items of tuple in an
ascending order.
Syntax: sorted(tuple)
Example: sorteddemo.py
num=(1,3,2,4,6,5)
lang=('java','c','python','cpp')
print(sorted(num))
print(sorted(lang))
Output:
python sorteddemo.py
(1, 2, 3, 4, 5, 6)
('c', 'cpp', 'java', 'python')
58. Tuple Functions & Methods in Python Cont..
☞ count():
• In python, count() method returns the number of times an element
appears in the tuple. If the element is not present in the tuple, it
returns 0.
Syntax: tuple.count(item)
Example: countdemo.py
num=(1,2,3,4,3,2,2,1,4,5,8)
cnt=num.count(2)
print("Count of 2 is:",cnt)
cnt=num.count(10)
print("Count of 10 is:",cnt) Output:
python countdemo.py
Count of 2 is: 3
Count of 10 is: 0
59. Tuple Functions & Methods in Python Cont..
☞ index():
• In python, index () method returns index of the passed element. If
the element is not present, it raises a ValueError.
• If tuple contains duplicate elements, it returns index of first
occurred element.
• This method takes two more optional parameters start and end
which are used to search index within a limit.
Syntax: tuple.index(item [, start[, end]])
Example: indexdemo.py
t1=('p','y','t','o','n','p')
print(t1.index('t'))
Print(t1.index('p'))
Print(t1.index('p',3,10))
Print(t1.index('z')) )
Output:
python indexdemo.py
2
0
5
Value Error
62. Strings in Python
• In python, strings can be created by enclosing the character or
the sequence of characters in the quotes.
• Python allows us to use single quotes, double quotes, or triple
quotes to create strings.
• In python, strings are treated as the sequence of characters
which means that python doesn't support the character data
type instead a single character written as 'p' is treated as the
string of length 1.
Example:
str1 = 'Hello Python'
str2 = "Hello Python"
str3 = '''Hello Python'''
64. String Indexing in Python
• Like other programming languages, the indexing of the python strings
starts from 0. For example, the string "HELLO" is indexed as given in
the below figure.
str="HELLO"
str[0]=H
str[1]=E
str[4]=O
• Python allows negative indexing for its sequences.
• The index of -1 refers to the last item, -2 to the second last item and
so on.
str[-1]=O
str[-2]=L
str[-4]=E
66. String Operators in Python
+ It is known as concatenation operator used to join the strings.
* It is known as repetition operator. It concatenates the multiple copies
of the same string.
[ ] It is known as slice operator. It is used to access the sub-strings of a
particular string.
[ : ] It is known as range slice operator. It is used to access the characters
from the specified range.
in It is known as membership operator. It returns if a particular sub-
string is present in the specified string.
not in It is also a membership operator and does the exact reverse of in. It
returns true if a particular substring is not present in the specified
string.
r/R It is used to specify the raw string. To define any string as a raw string,
the character r or R is followed by the string. Such as "hello n
python".
% It is used to perform string formatting. It makes use of the format
specifies used in C programming like %d or %f to map their values in
python.
67. String Operators in Python cont…
Example: “stropdemo.py”
str1 = "Hello"
str2 = " World"
print(str1*3) # prints HelloHelloHello
print(str1+str2) # prints Hello world
print(str1[4]) # prints o
print(str1[2:4]) # prints ll
print('w' in str1) # prints false as w is not present in str1
print('Wo' not in str2) # prints false as Wo is present in str2.
print(r'Hellon world') # prints Hellon world as it is written
print("The string str1 : %s"%(str1)) # prints The string str : Hello
Output: python ifdemo.py
HelloHelloHello
Hello World
o
ll
False
False
Hellon world
The string str1 : Hello
69. String Functions & Methods in Python
• Python provides various in-built functions & methods that are
used for string handling. Those are
☞ len():
• In python, len() function returns length of the given string.
Syntax: len(string)
• len()
• lower()
• upper()
• replace()
• join()
• split()
• find()
•index()
• isalnum()
• isdigit()
• isnumeric()
• islower()
• isupper()
Example: strlendemo.py
str1="Python Language"
print(len(str1))
Output:
python strlendemo.py
15
70. String Functions & Methods in Python Cont..
☞ lower ():
• In python, lower() method returns all characters of given string in
lowercase.
Syntax:
str.lower()
☞ upper ():
• In python, upper() method returns all characters of given string in uppercase.
Syntax:
str.upper()
Example: strlowerdemo.py
str1="PyTHOn"
print(str1.lower())
Output:
python strlowerdemo.py
python
Example: strupperdemo.py
str="PyTHOn"
print(str.upper())
Output:
python strupperdemo.py
PYTHON
71. String Functions & Methods in Python Cont..
☞ replace()
• In python, replace() method replaces the old sequence of
characters with the new sequence.
Syntax: str.replace(old, new[, count])
Example: strreplacedemo.py
str = "Java is Object-Oriented Java"
str2 = str.replace("Java","Python")
print("Old String: n",str)
print("New String: n",str2)
str3 = str.replace("Java","Python",1)
print("n Old String: n",str)
print("New String: n",str3)
Output: python strreplacedemo.py
Old String: Java is Object-Oriented and Java
New String: Python is Object-Oriented and Python
Old String: Java is Object-Oriented and Java
New String: Python is Object-Oriented and Java
72. String Functions & Methods in Python Cont..
☞ split():
• In python, split() method splits the string into a comma separated list.
The string splits according to the space if the delimiter is not provided.
Syntax: str.split([sep="delimiter"])
Example: strsplitdemo.py
str1 = "Python is a programming language"
str2 = str1.split()
print(str1);print(str2)
str1 = "Python,is,a,programming,language"
str2 = str1.split(sep=',')
print(str1);print(str2)
Output: python strsplitdemo.py
Java is a programming language
['Java', 'is', 'a', 'programming', 'language']
Java, is, a, programming, language
['Java', 'is', 'a', 'programming', 'language']
73. String Functions & Methods in Python Cont..
☞ find():
• In python, find() method finds substring in the given string and returns
index of the first match. It returns -1 if substring does not match.
Syntax: str.find(sub[, start[,end]])
Example: strfinddemo.py
str1 = "python is a programming language"
str2 = str1.find("is")
str3 = str1.find("java")
str4 = str1.find("p",5)
str5 = str1.find("i",5,25)
print(str2,str3,str4,str5)
Output:
python strfinddemo.py
7 -1 12 7
74. String Functions & Methods in Python Cont..
☞ index():
• In python, index() method is same as the find() method except it returns
error on failure. This method returns index of first occurred substring
and an error if there is no match found.
Syntax: str. index(sub[, start[,end]])
Example: strindexdemo.py
str1 = "python is a programming language"
str2 = str1.index("is")
print(str2)
str3 = str1.index("p",5)
print(str3)
str4 = str1.index("i",5,25)
print(str4)
str5 = str1.index("java")
print(str5)
Output:
python strindexdemo.py
7
12
7
Substring not found
75. String Functions & Methods in Python Cont..
☞ isalnum():
• In python, isalnum() method checks whether the all characters of the
string is alphanumeric or not.
• A character which is either a letter or a number is known as
alphanumeric. It does not allow special chars even spaces.
Syntax: str.isalnum()
Example: straldemo.py
str1 = "python"
str2 = "python123"
str3 = "12345"
str4 = "python@123"
str5 = "python 123"
print(str1. isalnum())
print(str2. isalnum())
print(str3. isalnum())
print(str4. isalnum())
print(str5. isalnum())
Output:
python straldemo.py
True
True
True
False
False
76. String Functions & Methods in Python Cont..
☞ isdigit():
• In python, isdigit() method returns True if all the characters in the string
are digits. It returns False if no character is digit in the string.
Syntax: str.isdigit()
Example: strdigitdemo.py
str1 = "12345"
str2 = "python123"
str3 = "123-45-78"
str4 = "IIIV"
str5 = "/u00B23" # 23
str6 = "/u00BD" # 1/2
print(str1.isdigit())
print(str2.isdigit())
print(str3.isdigit())
print(str4.isdigit())
print(str5.isdigit())
print(str6.isdigit())
Output:
python strdigitldemo.py
True
False
False
False
True
False
77. String Functions & Methods in Python Cont..
☞ isnumeric():
• In python, isnumeric() method checks whether all the characters of the
string are numeric characters or not. It returns True if all the characters
are numeric, otherwise returns False.
Syntax: str. isnumeric()
Example: strnumericdemo.py
str1 = "12345"
str2 = "python123"
str3 = "123-45-78"
str4 = "IIIV"
str5 = "/u00B23" # 23
str6 = "/u00BD" # 1/2
print(str1.isnumeric())
print(str2.isnumeric())
print(str3.isnumeric())
print(str4.isnumeric())
print(str5.isnumeric())
print(str6.isnumeric())
Output:
python strnumericldemo.py
True
False
False
False
True
True
78. String Functions & Methods in Python Cont..
☞ islower():
• In python, islower() method returns True if all characters in the string
are in lowercase. It returns False if not in lowercase.
Syntax: str.islower()
Example: strlowerdemo.py
str1 = "python"
str2="PytHOn"
str3="python3.7.3"
print(str1.islower())
print(str2.islower())
print(str3.islower())
Output:
python strlowerldemo.py
True
False
True
79. String Functions & Methods in Python Cont..
☞ isupper():
• In python string isupper() method returns True if all characters in the
string are in uppercase. It returns False if not in uppercase.
Syntax: str.isupper()
Example: strupperdemo.py
str1 = "PYTHON"
str2="PytHOn"
str3="PYTHON 3.7.3"
print(str1.isupper())
print(str2.isupper())
print(str3.isupper())
Output:
python strupperldemo.py
True
False
True