Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 15th, 2004, 12:50 PM
lauramccord lauramccord is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 180 lauramccord User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 9 h 3 m 58 sec
Reputation Power: 5
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.

Reply With Quote
  #2  
Old October 15th, 2004, 01:09 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Click here for more information.
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,717 Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Days 12 h 28 m 46 sec
Reputation Power: 1179
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

Reply With Quote
  #3  
Old October 18th, 2004, 09:34 PM
deltacoder's Avatar
deltacoder deltacoder is offline
slightly insane code guru
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jul 2004
Location: Indianapolis, IN
Posts: 871 deltacoder User rank is Sergeant (500 - 2000 Reputation Level)deltacoder User rank is Sergeant (500 - 2000 Reputation Level)deltacoder User rank is Sergeant (500 - 2000 Reputation Level)deltacoder User rank is Sergeant (500 - 2000 Reputation Level)deltacoder User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 h 8 m 36 sec
Reputation Power: 12
Send a message via AIM to deltacoder Send a message via MSN to deltacoder
and if you just mean "how many chars are there in a specified string":

Code:
str = "This is a test"
length = len(str)
__________________

deltacoder.com :: W3C Standards :: PHP.net :: Google

Last edited by deltacoder : October 19th, 2004 at 03:29 AM.

Reply With Quote
  #4  
Old October 19th, 2004, 01:07 AM
kancha kancha is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 23 kancha User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 48 m 25 sec
Reputation Power: 0
use slice.
eg:

str = "my string"
print str[:2]

will print my

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Need to know if there is a python function to...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT