Posts

Python OOPs Concepts

Python OOPs Concepts Like other general purpose languages, python is also an object-oriented language since its beginning. Python is an object-oriented programming language. It allows us to develop applications using an Object Oriented approach. In Python, we can easily create and use classes and objects. Major principles of object-oriented programming system are given below. ⦁ Object ⦁ Class ⦁ Method ⦁ Inheritance ⦁ Polymorphism ⦁ Data Abstraction ⦁ Encapsulation Object The object is an entity that has state and behavior. It may be any real-world object like the mouse, keyboard, chair, table, pen, etc. Everything in Python is an object, and almost everything has attributes and methods. All functions have a built-in attribute __doc__, which returns the doc string defined in the function source code. Class The class can be defined as a collection of objects. It is a logical entity that has some specific attributes and methods. For example: if you have an employee c...

List methods

Python List append() Method Python append() method adds an item to the end of the list. It appends an element by modifying the list. The method does not return itself. The item can also be a list or dictionary which makes a nested list. Method is described below. Signature append(x)  Parameters x: It can be a number, list, string, dictionary etc. Return It does not return any value rather modifies the list. Python List append() Method Example 1 First, let's see a simple example which appends elements to the list. # Python list append() Method  # Creating a list  list = ['1','2','3']  for l in list:  # Iterating list      print(l)  # Appending element to the list  list.append(4)    print("List after appending element : ",list) # Displaying list  Output: 1 2 3 List after appending element :  ['1', '2', '3', 4] Python List append() Method Example 2 Appending a list to the list is also possible w...

python file handling

Python File Handling Till now, we were taking the input from the console and writing it back to the console to interact with the user. Sometimes, it is not enough to only display the data on the console. The data to be displayed may be very large, and only a limited amount of data can be displayed on the console, and since the memory is volatile, it is impossible to recover the programmatically generated data again and again. Opening a file Python provides the open() function which accepts two arguments, file name and access mode in which the file is accessed. The function returns a file object which can be used to perform various operations like reading, writing, etc. The syntax to use the open() function is given below. ⦁ file object = open(<file-name>, <access-mode>, <buffering>)    The files can be accessed using various modes like read, write, or append. The following are the details about the access mode to open a file. SN Access mode Descrip...
Image
Home Learn Python Basics Lists Dictionary Code Snippets Modules Home >> Lists Dec. 25, 2012   Lists Lists This is a new serie of articles here at Python for beginners, that are supposed to be a starting point for completely beginners of Python. See it as a cheat sheet, reference, manual or whatever you want. The purpose is to very short write down the basics of Python. This page will describe how to use lists in Python. What is a List? The simplest data structure in Python and is used to store a list of values. Lists are collections of items (strings, integers, or even other lists). Each item in the list has an assigned index value. Lists are enclosed in [ ] Each item in a list is separated by a comma Unlike strings, lists are mutable, which means they can be change...