Category "python tutorial"

on in python tutorial

Previous Python lets you create and define an object-oriented class that can be used to associate code with the data that it operates on. The following is the form of class in Python. class <name>:   def <method name>(<arguments>):     <method codes suit> Create a sample class: Let’s create a sample vehicle class for......

[ Click to Continue ]
on in python tutorial

Previous | Next A module is simply a text file that contains Python code. Your code will become highly reusable when your turn them into a module. Create and save your code: To turn your function into a module, save your code into a Python extension file. Let’s save the following code into a Python......

[ Click to Continue ]
on in python tutorial

Previous | Next Comment you code: It’s always a good idea to include comments with your code. A well-written comments help to document your work and make it easy to understand by someone who will work on your code in future. Use a triple quote for multiple-line comments. >>> def ReturnTotal(x, y)   '''This function......

[ Click to Continue ]
on in python tutorial

Previous | Next You might experience the traceback error message whenever something goes wrong with your code. If you are not, try with the following example which we divide a value with zero. >>> def test():   1/0   >>> test() Traceback (most recent call last):   File "<pyshell#24>", line 1, in <module>    ......

[ Click to Continue ]
on in python tutorial

Previous | Next A function is like a little program that you can use to perform a specific action. Python has a lot of functions that can do many wonderful things. However, it may not always be the ideal function that you are looking for. At that time, you will need to create your own......

[ Click to Continue ]
on in python tutorial

Previous | Next String is used to represent text which comprised of a set of characters that can be spaces, numbers, etc. Python’s strings support the sequence type method which means you can deal with the string by using sequence type method like splitting, slicing, indexing, membership, length, etc. Strings are immutable, so all kinds......

[ Click to Continue ]
on in python tutorial

Previous | Next List is one of the Python’s built-in types of sequences. When you create a list in Python, the interpreter creates an array-like data structure in memory to hold your data, with your data items stacked from the bottom up. Like array technology in other programming languages, the first slot in the stack......

[ Click to Continue ]
on in python tutorial

Previous | Next List is great when it come to group values into a structure and refer to each value by number. There is another useful data type built into Python called dictionary. The Python dictionary lets you organize your data for speedy lookup by associating your data with names or keys, not numbers.  Dictionary......

[ Click to Continue ]
on in python tutorial

Previous | Next Tuple is similar to list except that it doesn’t allow the sequence to change. That also mean, once data is assigned to a tuple, the data they hold cannot be changed under any circumstances. tuple is useful especially if your function is designed to return a set of constant list which doesn’t......

[ Click to Continue ]
on in python tutorial

Previous | Next Usually, a loop simply executes a block until its condition becomes false, or until it has used up all sequence elements. But sometimes you may want to interrupt the loop, to start a new iteration (one “round” of executing the block), or to simply end the loop. break With break, it allow......

[ Click to Continue ]