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. :notworthy
Re: How to use Strings in Python
If you want to know the basic things about the expressions, then I suggest you should refer http://forums.techarena.in/software-...nt/1383840.htm. 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.
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 "" "
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].
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 ().
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.