You are on page 1of 11

Fundamentals

Of

Python Programming

D. Prashanth Kumar

Dr. K. Praveen Kumar Rao

Reyaan Publishers

Hyderabad
National wide circulation
First published in 2021
by
Reyaan Publishers
Hyderabad
e-mail: reyaanpublishersdelhi@gmail.com
Phone: 9391605029

Fundamentals of Python Programming


Copyright@D. Prashanth Kumar & Dr. K. Praveen Kumar Rao

Disclaimer
Concerned authors are solely responsible for their views, opinions, policies, copyright
infringement, legal action, penalty or loss of any kind regarding their articles. Neither the
publisher nor the editor will be responsible for any penalty or loss of any kind if claimed
in future. Contributing authors have no right to demand any royalty amount for their
articles.

Printed in India
Preface
This book provides an introduction to the concepts of Python Programming. Python is an
open source programming language which is used for standalone programs andscripting
applications in variety of domains. Python is free, portable, powerful, easy and fun to use.
The programmers from the software industryfound Python’s focus on developer
productivity and software quality. It has been very advantageous in both large and small
projects.

The book’s goal is to make the readers quickly understand and gain knowledge on the
fundamentals of the core Python language. This book is also useful for the beginners and
advanced learners. Whether the reader is new to programming or professional developer,
this book quickly introduces the fundamentals of the core Python language.After reading
this book, the reader gains ample knowledge about Python and would be able to apply it
in any application domain he/she chooses to explore.

This book is more than a tutorial which focuses on the concepts of Core Python
Language. The book also focuses on Python’s nature in the domains like Web, GUIs and
databases. The book helps the programmers with the fundamentals of Python
programming and gives in-depth knowledge to those learning the language for the first
time.

The topics covered in this book are found mostly useful and interesting in programming.
The interested readers should progress by learning the basic concepts from this book.

The book is structured in such a way that the beginners of Python Programming would
find it easy and understandable. All the topics covered in the book are important and
useful.

D. Prashanth Kumar

Dr. K. Praveen Kumar Rao


To
Beloved family members
And
Well-wishers
CONTENTS
Preface
Acknowledgement

CHAPTER - 1 01
1.1 What is Python 01
1.2 Python Features 01
1.3 Python History and Versions 03
1.4 Python Variables 04
1.5 Python Data Types 14
1.6 Python Keywords 21
1.7 Python Operators 31
1.8 Python Comments 38

CHAPTER - 2 42
2.1 Python If-else statements 42
2.2 Python Loops 49
2.3 Python for loop 50
2.4 Python While loop 57
2.5 Python break statement 63
2.6 Python continue Statement 66
2.7 Python Pass 69

CHAPTER - 3 71
3.1 Python String 71
3.2 Python List 87
3.3 Python Tuple 98
3.4 Python Set 106
3.5 Python Dictionary 121

CHAPTER - 4 132
4.1 Python Function 132
4.2 Python Lambda Functions 144

CHAPTER - 5 146
5.1 Python File Handling 146
5.2 Python Modules 162

CHAPTER - 6 168
6.1 Python Exception 168
6.1.1 Common Exceptions 168
6.1.2 Exception handling in python 169
6.1.3 Declaring Multiple Exceptions 174
6.1.4 The try...finally block 175
6.1.5 Raising exceptions 177

CHAPTER - 7 180
7.1 Python Date and time 180
7.1.1 Tick 180
7.1.2 How to get the current time? 181
7.1.3 Time tuple 181
7.1.4 Getting formatted time 182
7.1.5 Python sleep time 182
7.1.6 The datetime Module 183
7.1.7 Creating date objects 183
7.1.8 Comparison of two dates 184
7.1.9 The calendar module 184

CHAPTER - 8 187
8.1 Python Regular Expressions 187
8.1.1 Regex Functions 187
8.1.2 Forming a regular expression 188
8.1.2.1 Meta-Characters 188
8.1.2.2 Special Sequences 189
8.1.2.3 Sets 190
8.1.2.4 The findall() function 191
8.1.2.5 The match object 191
8.2 Python Math Module 192
8.3 Python Random module 195
8.4 Python Arrays 197
8.4.1 Array Representation 198
8.4.2 Array operations 198
8.4.3 How to change or add elements 199
8.4.4 Why to use arrays in Python? 199
8.4.5 Finding the length of an array 200
8.4.6 Array Concatenation 200
8.5 Python Command line arguments 201
8.5.1 What is an argument passing? 201
8.5.2 Python sys module 202
8.5.3 Python getopt module 202
8.5.4 Python argparse module 203
8.5.5 How to use command line arguments in python? 205

CHAPTER - 9 207
9.1 Python OOPs Concepts 207
9.2 Python Class and Objects 210
9.3 Python Constructor 213
9.4 Python Inheritance 220
9.5 Abstraction in Python 229

CHAPTER - 10 234
Database Connectivity (MySQL) using Python 234
10.1 Install mysql.connector 234
10.2 Database Connection 234
10.2.1 Creating the connection 235
10.2.2 Creating a cursor object 236
10.2.3 Creating new databases 237
10.3 Creating the new database 238
10.4 Creating the table 239
1.5 Insert Operation 241
10.6 Read Operation 245
10.7 Update Operation 253
10.8 Join Operation 255
10.9 Performing Transactions 260

CHAPTER - 11 263
11.1 GUI using Python: Tkinter 263
11.2 Python Tkinter Button 270
11.3 Python Tkinter Canvas 273
11.4 Python TkinterCheckbutton 276
11.5 Python Tkinter Entry 280
11.6 Python Tkinter Frame 287
11.7 Python Tkinter Label 289
11.8 Python TkinterListbox 291
11.9 Python TkinterMenubutton 297
11.9 Python Tkinter Menu 300
11.10 Python Tkinter Message 305
11.11 Python TkinterRadiobutton 308
11.12Tkintermessagebox 313

You might also like