Skip to content

This is a public repository of Jupyter notebooks with introductory tutorials on different aspects of Python programming. Please star us if you think it is useful:

Notifications You must be signed in to change notification settings

mohd-faizy/learn_python

Repository files navigation

author made-with-Markdown Language Maintained Last Commit contributions welcome Size

Python is a high-level, general-purpose and a very popular programming language.It was created by Guido van Rossum in 1991. Python programming language (latest Python 3) is being used in web development, Machine Learning applications, along with all cutting edge technology in Software Industry. Python Programming Language is very well suited for Beginners, also for experienced programmers with other programming languages like C++ and Java.

Python Data Structure

Premitive Non-Premitive
  Built-in User-defined
Integer List Stack
Float Tuple Queue
String Dictionary Tree
Boolean Set Graph

Below are some facts about Python Programming Language:

  1. Python is currently the most widely used multi-purpose,high-level programming language.

  2. Python allows programming in Object-Oriented and Procedural paradigms.

  3. Python programs generally are smaller than other programming languages like Java. Programmers have to type relatively less and indentation requirement of the language,makes them readable all the time.

  4. Python language is being used by almost all tech-giant companies like-Google,Amazon, Facebook,Instagram,Dropbox,Uber ... etc.

  5. The biggest strength of Python is huge collection of standard library which can be used for the following:

    • Machine Learning GUI Applications(like Kivy,Tkinter,PyQt etc.)
    • Web frameworks like Django(used by YouTube,Instagram,Dropbox)
    • Image processing(like OpenCV,Pillow)
    • Web scraping(like Scrapy,BeautifulSoup,Selenium)
    • Test frameworks
    • Multimedia
    • Scientific computing
    • Text processing and many more ..

Python Advantages and Disadvantages

Advantages of Python

  1. Presence of third-party modules
  2. Extensive support libraries(NumPy for numerical calculations, Pandas for data analytics, etc.)
  3. Open source and large active community base
  4. Versatile, Easy to read, learn and write
  5. User-friendly data structures
  6. High-level language
  7. Dynamically typed language(No need to mention data type based on the value assigned, it takes data type)
  8. Object-Oriented and Procedural Programming language Portable and Interactive
  9. Ideal for prototypes – provide more functionality with less coding
  10. Highly Efficient(Python’s clean object-oriented design provides enhanced process control, and the language is equipped with excellent text processing and integration capabilities, as well as its own unit testing framework, which makes it more efficient.)
  11. Internet of Things(IoT) Opportunities
  12. Interpreted Language
  13. Portable across Operating systems

Disadvantages of Python

  1. Slow Speed We discussed above that Python is an interpreted language and dynamically-typed language. The line by line execution of code often leads to slow execution. The dynamic nature of Python is also responsible for the slow speed of Python because it has to do the extra work while executing code. So, Python is not used for purposes where speed is an important aspect of the project.

  2. Not Memory Efficient To provide simplicity to the developer, Python has to do a little tradeoff. The Python programming language uses a large amount of memory. This can be a disadvantage while building applications when we prefer memory optimization.

  3. Weak in Mobile Computing Python is generally used in server-side programming. We don’t get to see Python on the client-side or mobile applications because of the following reasons. Python is not memory efficient and it has slow processing power as compared to other languages.

  4. Database Access Programming in Python is easy and stress-free. But when we are interacting with the database, it lacks behind. The Python’s database access layer is primitive and underdeveloped in comparison to the popular technologies like JDBC and ODBC. Huge enterprises need smooth interaction of complex legacy data and Python is thus rarely used in enterprises.

  5. Runtime Errors As we know Python is a dynamically typed language so the data type of a variable can change anytime. A variable containing integer number may hold a string in the future, which can lead to Runtime Errors.

Therefore Python programmers need to perform thorough testing of the applications.

Applications

  1. GUI-based desktop applications
  2. Graphic design, image processing applications, Games, and Scientific/ computational Applications
  3. Web frameworks and applications
  4. Enterprise and Business applications
  5. Operating Systems
  6. Education
  7. Database Access
  8. Language Development
  9. Prototyping
  10. Software Developmen

Organizations using Python

  1. Google(Components of Google spider and Search Engine)
  2. Yahoo(Maps)
  3. YouTube
  4. Mozilla
  5. Dropbox
  6. Microsoft
  7. Cisco
  8. Spotify
  9. Quora
  10. Facebook

LANGUAGE FEATURES

Interpreted:

There are no separate compilation and execution steps likeCandC++.

  • Directly run the program from the source code.
  • Internally,Python converts the source code into an intermediate form called bytecodes which is then translated into native language of specific computer to run it.
  • No need to worry about linking and loading with libraries,etc.

Platform Independent:

  • Python programs can be developed and executed on multiple operating system platforms.
  • Python can be used on Linux,Windows,Macintosh,Solaris and many more.

Free and Open Source: Redistributable

High-level Language:

  • In Python,no need to take care about low-level details such as managing the memory used by the program.

Simple:

  • Closer to English language;Easy to Learn.
  • More emphasis on the solution to the problem rather than the syntax.

Embeddable:

  • Python can be used with in C/C++ program to give scripting capabilities for the program's users.

Robust:

  • Exceptional handling features
  • Memory management techniques in built

Rich Library Support:

  • The Python Standard Library is very vast.
  • Known as the"batteries included"philosophy of Python;It can help do various things involving regular expressions,documentation generation,unit testing, threading,databases,web browsers CGI,email,XML,HTML,WAV files, cryptography,GUI and many more.
  • Besides the standard library,there are various other high-quality libraries such as the Python Imaging Library which is an amazingly simple image manipulation library.

Python in One Picture

⭐Python list methods

Method Description
🟥Adding and Removing Elements
append(x) Add an element x to the end of the list.
clear() Remove all items from the list.
copy() Return a shallow copy of the list.
extend(iterable) Extend the list by appending all elements from an iterable (like another list or tuple).
insert(i, x) Insert an element x at a given position i. The first argument is the index of the element before which to insert.
pop(i=-1) Remove and return the element at index i (defaults to the last element).
remove(x) Remove the first item from the list whose value is equal to x. Raises a ValueError if there is no such item.
🟥Ordering and Searching
count(x) Return the number of occurrences of element x in the list.
index(x, i=0, j=len(list)) Return the index of the first occurrence of element x within the range [i, j). Raises a ValueError if there is no such item.
reverse() Reverse the elements of the list in place.
sort(key=None, reverse=False) Sort the items of the list in place (ascending by default). You can optionally provide a custom key function and specify reverse order.
🟥Other List Operations
__contains__(x) Check if an element x is present in the list (same as in operator).
__getitem__(i) Access elements by index.
__setitem__(i, x) Assign elements to a specific index.
__delitem__(i) Remove elements at a specific index.
__len__() Return the length (number of elements) of the list.
🟥Additional Methods
all(iterable) Return True if all elements of an iterable are true (often used with lists).
any(iterable) Return True if any element of an iterable is true (often used with lists).
enumerate(iterable, start=0) Return an enumerate object that yields pairs of (index, value) for elements in an iterable (like a list).
filter(function, iterable) Construct an iterator from elements of an iterable for which a function returns True (often used with lists).
map(function, iterable1, ...) Apply a function to all elements of an iterable (like a list) and return an iterator.
min(iterable) Return the smallest item in an iterable (or the list).
max(iterable) Return the largest item in an iterable (or the list).
sum(iterable, start=0) Return the sum of elements of an iterable (like a list) or the start value.
sorted(iterable, key=None, reverse=False) Return a new sorted list from the items in an iterable (like a list).

⭐Python string methods

Method Description
🟥String Manipulation
Slicing Extract substrings using square brackets [].
Concatenation Combine strings using the + operator.
Membership Testing Check if a substring exists using the in operator.
Formatting Create formatted strings with f-strings or the .format() method.
🟥Case Conversion
upper() Convert all characters to uppercase.
lower() Convert all characters to lowercase.
title() Convert the first character of each word to uppercase.
capitalize() Convert the first character of the string to uppercase.
swapcase() Swap the case of all characters.
🟥Whitespace Removal
strip() Remove leading and trailing whitespaces.
lstrip() Remove leading whitespaces.
rstrip() Remove trailing whitespaces.
🟥Searching and Replacing
find(substring) Find the index of the first occurrence of a substring.
rfind(substring) Find the index of the last occurrence of a substring.
count(substring) Count the number of occurrences of a substring.
replace(old, new, count) Replace occurrences of a substring with another substring (optional count).
🟥Splitting and Joining
split(sep) Split a string into a list of substrings using a separator.
rsplit(sep) Split a string into a list of substrings, starting from the end.
join(iterable) Join elements from an iterable (like a list) into a string using a separator.
🟥Alignment
center(width, fillchar) Center-align the string within a specified width using a fill character.
ljust(width, fillchar) Left-justify the string within a specified width using a fill character.
rjust(width, fillchar) Right-justify the string within a specified width using a fill character.
🟥Other Methods
isalnum() Check if all characters are alphanumeric.
isalpha() Check if all characters are alphabetic.
isdigit() Check if all characters are digits.
islower() Check if all characters are lowercase.
isupper() Check if all characters are uppercase.
isspace() Check if all characters are whitespace.
istitle() Check if the string is in title case.
isidentifier() Check if the string is a valid identifier.
zfill(width) Fill the string with zeros on the left side to a specified width.
expandtabs(tabsize) Expand tabs in the string to spaces (default tab size is 8).
encode(encoding) Encode the string using a specified encoding (e.g., 'utf-8').
decode(encoding) Decode the string using a specified encoding (e.g., 'utf-8').
partition(sep) Partition the string into three parts: a part before the first occurrence of sep, sep itself, and a part after sep.
rpartition(sep) Partition the string from the right.
startswith(prefix) Check if the string starts with a specified prefix.
endswith(suffix) Check if the string ends with a specified suffix.
index(substring) Similar to find(), but raises a ValueError if the substring is not found.
casefold() Convert string to lowercase, suitable for case-insensitive comparisons.
format_map(mapping) Format the string using a mapping dictionary.

⭐Python dict methods

Method Description
🟥Adding and Removing Items
clear() Remove all items from the dictionary.
copy() Return a shallow copy of the dictionary.
fromkeys(iterable, value=None) Create a new dictionary with keys from iterable and values set to value (defaults to None).
pop(key, default=None) Remove the item with the given key and return its value. If the key is not found, return the default value (defaults to None).
popitem(last=True) Remove and return a (key, value) pair from the dictionary. By default, removes the last inserted pair. You can set last=False to remove from the beginning.
setdefault(key, default=None) Return the value for the key if it exists. Otherwise, insert the key with the default value and return that value.
🟥Retrieving and Modifying Values
get(key, default=None) Return the value for the key if it exists. Otherwise, return the default value (defaults to None).
items() Return a view object of the dictionary's key-value pairs as tuples.
keys() Return a view object of the dictionary's keys.
update(other, **kwargs) Update the dictionary with key-value pairs from another dictionary (other) and optional keyword arguments (**kwargs).
values() Return a view object of the dictionary's values.
🟥Membership and Lookups
__contains__(key) Check if a key exists in the dictionary (same as in operator).
__getitem__(key) Get the value for the key. Raises a KeyError if the key is not found.
🟥Other Methods
__setitem__(key, value) Assign a value to a key.
__delitem__(key) Remove the key and its corresponding value. Raises a KeyError if the key is not found.
__len__() Return the number of items in the dictionary.
🟥Additional Considerations
Dictionary methods typically return view objects, which provide a dynamic view of the dictionary's contents. Modifying the dictionary while iterating over a view object might raise errors. Consider creating a copy of the view object or the dictionary itself if you need to modify it during iteration.

⭐Python tuple methods

Method Description
count(x) This method counts the number of occurrences of the element x within the tuple.
Example: my_tuple = (1, 2, 3, 2, 1) count(2) will return 2
index(x, start=0, end=len(tuple)) This method returns the index of the first occurrence of the element x within the specified range [start, end]. Raises a ValueError if the element is not found.
Example: my_tuple = ("apple", "banana", "cherry", "banana") index("banana") will return 1 (index of the first "banana") index("banana", 2) will return 3 (index of the second "banana")
🟥Additional Considerations
Since tuples are immutable, methods like append, insert, remove, or pop (used for modifying lists) are not available for tuples.
You can use techniques like creating a new tuple with the desired modifications or converting the tuple to a list, modifying the list, and then converting it back to a tuple if needed.
For more information on tuples and their properties, you can refer to the official Python documentation.

⭐python set methods

Method Description
🟥Adding Elements
add(element) Adds an element to the set. Since sets cannot have duplicates, if the element already exists, nothing happens.
🟥Removing Elements
clear() Removes all elements from the set.
discard(element) Removes the element from the set if it exists. If the element is not present, no error is raised (unlike remove).
pop(element=None) Removes and returns an arbitrary element from the set. Raises a KeyError if the set is empty. You can optionally specify an element to remove, but if it's not found, a KeyError is still raised.
remove(element) Removes the element from the set. Raises a KeyError if the element is not present.
🟥Modifying Sets
update(iterable) Updates the set by adding elements from an iterable (like another set or list). Duplicates are removed.
🟥Set Operations (Return New Sets)
difference(other) Returns a new set with elements in the first set but not in other.
difference_update(other) Removes elements from the set that are also in other. Modifies the original set.
intersection(other) Returns a new set with elements common to both sets.
intersection_update(other) Updates the set to contain only elements also present in other. Modifies the original set.
symmetric_difference(other) Returns a new set with elements that are in either set but not in both.
symmetric_difference_update(other) Updates the set with elements that are in either set but not in both. Modifies the original set.
union(other) Returns a new set with elements from both sets. Duplicates are not removed.
isdisjoint(other) Returns True if the sets have no common elements, False otherwise.
issubset(other) Returns True if all elements in the set are also in other, False otherwise.
issuperset(other) Returns True if all elements in other are also in the set, False otherwise.
🟥Other Methods
copy() Returns a shallow copy of the set.
pop() Same as the pop method mentioned earlier (removes and returns an arbitrary element).
🟥Additional Considerations
Since sets are unordered collections, the order in which elements are added or removed might not be reflected in the set's contents. Methods that return new sets (difference, intersection, symmetric_difference, and union) create new sets without modifying the original ones.

$\color{skyblue}{\textbf{Connect with me:}}$


Releases

No releases published

Packages

No packages published