Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How to use Strings in Python

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 31-12-2010
Member
 
Join Date: Jul 2010
Posts: 25
How to use Strings in Python
  

I am studying the Python, and let me tell you that I am newbie to this programming language. I have now stuck into the strings and string index. Now I am not having any knowledge about these expressions. So, I thought to ask you about it. I am sure that many scholars must be hanging over here, who must be knowing much basic things about the strings and other expressions. I am also having some doubts in conversions as well. I know that I am posting many doubts in one thread, but since I am newbie, I want to know all these things. So I am expecting some help from your side earlier.

Reply With Quote
  #2  
Old 31-12-2010
Member
 
Join Date: May 2008
Posts: 222
Re: How to use Strings in Python

If you want to know the basic things about the expressions, then I suggest you should refer What are an expressions used in python?. Strings are sequences of characters, and have a characteristic to be immutable. This means that once defined a string, its contents can not change. In general, if you want to get a string that has a different character than a string that already exists, you must create a new one. This is the meaning of its immutability.
Reply With Quote
  #3  
Old 31-12-2010
Member
 
Join Date: Nov 2008
Posts: 52
Re: How to use Strings in Python

To express a string I just put it in quotes, which may be single or double. No matter what the delimiter, the important thing is that if defines a string with single quotes, I can use inside the double quotes and vice versa. One trick that allows you to enter a string number line is obtained with the backslash symbol immediately before the end of the line. Simply deletes the backslash character, and the end of the line that follows it. This method is not very comfortable, and was in fact invented the triple quote method. And in practice it can start a string that spans multiple lines of text in a program simply started with 3 double quotation marks, and ending by as many double quotation marks. The idea is that this sequence ("") is quite unlikely that we need a plain text. For this reason it is used as a marker of the beginning and end of many string line. Here's an example:
Code:
  print "" "Welcome.
 Press 1 for options 
 Perm 0 to exit "" "
Reply With Quote
  #4  
Old 31-12-2010
Member
 
Join Date: Nov 2008
Posts: 94
Re: How to use Strings in Python

You should know that the strings are special case of sequences. The basic idea is that they are "indexed". Or you can extract for example the fifth character in it, simply with the syntax: s [4]. Note that this does not change the immutability of strings. Read a character does not mean you can change. Note that this does not change the immutability of strings. Read a character does not mean you can change. A feature of the indices is that they can also be negative. In this case count from the end. So if we have s = "hello", the first digit, c, s [0] (the first index is always 0). Instead, the last character and obtained with s [-1].
Reply With Quote
  #5  
Old 31-12-2010
Member
 
Join Date: Nov 2008
Posts: 73
Re: How to use Strings in Python

A feature of indexation, which have strings (and other sequences), it is possible to select a sub-sequence, using the so-called slice. This is simply the syntax s [2:3]. In this way we get a sub-sequence that contains all the characters from the second to include the excluded. Consider the syntax for a slice: s [2:3], you can omit the start or end. If you omit the start, the value is not expressed coincides with 0 (s [: 3] as s [0:3]), if you omit the end, coincides with the end of the sequence: s [2:] from the items from the third at the end. A function that is used to count the elements of a sequence is simply the function len ().
Reply With Quote
  #6  
Old 31-12-2010
Member
 
Join Date: Feb 2009
Posts: 39
Re: How to use Strings in Python

From the moment we have different types of numbers, for example, you may need to convert from one to another. In general, the conversions occur implicitly. For example, if an entire high and a long integer, I get a long integer. If you add a long integer to a floating point number, I get floating point numbers. Sometimes you have to explicitly convert a number of one type to another type of number. This is achieved using the function float (), long () or int (). Usually this happens when you want to convert a larger type to a smaller type. For example, when you have a floating point number, and you want to get an integer. Explicit conversions can be made between non-complex numbers. I can not convert a complex number to a number, this is a math problem. What I can do is extract the imaginary part (z.imag), the real part (z.real) or calculate the length (abs ()), but things can be done.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to use Strings in Python"
Thread Thread Starter Forum Replies Last Post
Difference between two strings Aman 1 Software Development 5 03-12-2013 11:59 AM
Files and strings in C An1990 Software Development 2 10-05-2012 10:11 PM
Strings in JavaFX Messenger Software Development 3 16-07-2010 04:57 PM
Struct and Strings in C Ash maker Software Development 5 05-04-2010 12:31 PM
Download Python 3.0 / Python 3000 Amaresh Software Development 6 24-02-2009 09:28 AM


All times are GMT +5.5. The time now is 07:28 AM.