Results 1 to 6 of 6

Thread: How to use Strings in Python

  1. #1
    Join Date
    Jul 2010

    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.

  2. #2
    Join Date
    May 2008

    Re: How to use Strings in Python

    If you want to know the basic things about the expressions, then I suggest you should refer 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.

  3. #3
    Join Date
    Nov 2008

    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:
      print "" "Welcome.
     Press 1 for options 
     Perm 0 to exit "" "

  4. #4
    Join Date
    Nov 2008

    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].

  5. #5
    Join Date
    Nov 2008

    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 ().

  6. #6
    Join Date
    Feb 2009

    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.

Similar Threads

  1. Difference between two strings
    By Aman 1 in forum Software Development
    Replies: 5
    Last Post: 03-12-2013, 11:59 AM
  2. Files and strings in C
    By An1990 in forum Software Development
    Replies: 2
    Last Post: 10-05-2012, 10:11 PM
  3. Strings in JavaFX
    By Messenger in forum Software Development
    Replies: 3
    Last Post: 16-07-2010, 04:57 PM
  4. Struct and Strings in C
    By Ash maker in forum Software Development
    Replies: 5
    Last Post: 05-04-2010, 12:31 PM
  5. Download Python 3.0 / Python 3000
    By Amaresh in forum Software Development
    Replies: 6
    Last Post: 24-02-2009, 09:28 AM

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Page generated in 1,660,970,726.95379 seconds with 16 queries