|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need to know if there is a python function to...
I need to return x number of chars in a string. Is there a function for this?
Thanks. |
|
#2
|
||||
|
||||
|
Nope, there isn't a function. Just treat the string as if it were a list:
Code:
str = "This is a test" str2 = str[2:10] print str print str2 See? Who needs a function when python has a built-in operator for this ![]()
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month |
|
#3
|
||||
|
||||
|
and if you just mean "how many chars are there in a specified string":
Code:
str = "This is a test" length = len(str) Last edited by deltacoder : October 19th, 2004 at 03:29 AM. |
|
#4
|
|||
|
|||
|
use slice.
eg: str = "my string" print str[:2] will print my |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Need to know if there is a python function to... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|