
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 26504 Articles for Server Side Programming

22K+ Views
Python includes the following list functions −Sr.NoFunction with Description1cmp(list1, list2)Compares elements of both lists.2len(list)Gives the total length of the list.p>3max(list)Returns item from the list with max value.4min(list)Returns item from the list with min value.5list(seq)Converts a tuple into list.Python includes following list methodsSr.NoMethods with Description1list.append(obj)Appends object obj to list2list.count(obj)Returns count of how many times obj occurs in list3list.extend(seq)Appends the contents of seq to list4list.index(obj)Returns the lowest index in list that obj appears5list.insert(index, obj)Inserts object obj into list at offset index6list.pop(obj=list[-1])Removes and returns last object or obj from list7list.remove(obj)Removes object obj from list8list.reverse()Reverses objects of list in place9list.sort([func])Sorts objects of list, use ... Read More

2K+ Views
Lists respond to the + and * operators much like strings; they mean concatenation and repetition here too, except that the result is a new list, not a string.In fact, lists respond to all of the general sequence operations we used on strings in the prior chapter.Python ExpressionResultsDescriptionlen([1, 2, 3])3Length[1, 2, 3] + [4, 5, 6][1, 2, 3, 4, 5, 6]Concatenation['Hi!'] * 4['Hi!', 'Hi!', 'Hi!', 'Hi!']Repetition3 in [1, 2, 3]TrueMembershipfor x in [1, 2, 3]: print x,1 2 3Iteration

344 Views
To remove a list element, you can use either the del statement if you know exactly which element(s) you are deleting or the remove() method if you do not know.Example Live Demo#!/usr/bin/python list1 = ['physics', 'chemistry', 1997, 2000]; print list1 del list1[2]; print "After deleting value at index 2 : " print list1OutputWhen the above code is executed, it produces the following result −['physics', 'chemistry', 1997, 2000] After deleting value at index 2 : ['physics', 'chemistry', 2000]Note − remove() method is discussed in subsequent section.

51K+ Views
In Python, lists are one of the built-in data structures that are used to store collections of data. The lists are mutable, which means we can modify its element after it is created. You can update single or multiple list elements using append, insert, extend, remove, and clear to change the list content by adding, updating, or removing elements from the list object. In this article, we will discuss how we can update an existing element in the list. The list is an index-based sequential data structure so that we can access the list elements by their index position, ... Read More

483 Views
To access values in lists, use the square brackets for slicing along with the index or indices to obtain value available at that index.Example Live Demo#!/usr/bin/python list1 = ['physics', 'chemistry', 1997, 2000]; list2 = [1, 2, 3, 4, 5, 6, 7 ]; print "list1[0]: ", list1[0] print "list2[1:5]: ", list2[1:5]OutputWhen the above code is executed, it produces the following result −list1[0]: physics list2[1:5]: [2, 3, 4, 5]

4K+ Views
Python includes the following built-in methods to manipulate strings −Sr.NoFunction & Description1capitalize()Capitalizes first letter of string2center(width, fillchar)Returns a space-padded string with the original string centered to a total of width columns.3count(str, beg= 0, end=len(string))Counts how many times str occurs in string or in a substring of string if starting index beg and ending index end are given.4decode(encoding='UTF-8', errors='strict')Decodes the string using the codec registered for encoding. encoding defaults to the default string encoding.5encode(encoding='UTF-8', errors='strict')Returns encoded string version of string; on error, default is to raise a ValueError unless errors is given with 'ignore' or 'replace'.6endswith(suffix, beg=0, end=len(string))Determines if string or ... Read More

3K+ Views
Normal strings in Python are stored internally as 8-bit ASCII, while Unicode strings are stored as 16-bit Unicode. This allows for a more varied set of characters, including special characters from most languages in the world. I'll restrict my treatment of Unicode strings to the following −Example Live Demo#!/usr/bin/python print u'Hello, world!'OutputWhen the above code is executed, it produces the following result −Hello, world! As you can see, Unicode strings use the prefix u, just as raw strings use the prefix r.

6K+ Views
Python's triple quotes comes to the rescue by allowing strings to span multiple lines, including verbatim NEWLINEs, TABs, and any other special characters.The syntax for triple quotes consists of three consecutive single or double quotes.Example Live Demo#!/usr/bin/python para_str = """this is a long string that is made up of several lines and non-printable characters such as TAB ( \t ) and they will show up that way when displayed. NEWLINEs within the string, whether explicitly given like this within the brackets [ ], or just a NEWLINE within the variable assignment will also show up. """ print para_strOutputWhen the above code is ... Read More

3K+ Views
Assume string variable a holds 'Hello' and variable b holds 'Python', then −Sr.NoOperator & DescriptionExample1+Concatenation - Adds values on either side of the operatora + b will give HelloPython2*Repetition - Creates new strings, concatenating multiple copies of the same stringa*2 will give-HelloHello3[]Slice - Gives the character from the given indexa[1] will give e4[ : ]Range Slice - Gives the characters from the given rangea[1:4] will give ell5inMembership - Returns true if a character exists in the given stringH in a will give 16not inMembership - Returns true if a character does not exist in the given stringM not in a ... Read More

3K+ Views
You can "update" an existing string by (re)assigning a variable to another string. The new value can be related to its previous value or to a completely different string altogether. For example −Example Live Demo#!/usr/bin/python var1 = 'Hello World!' print "Updated String :- ", var1[:6] + 'Python'OutputWhen the above code is executed, it produces the following result −Updated String :- Hello Python