![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Aug 2005
Posts: 2
Rep Power: 0
![]() |
I'm a new to Python
Hey guys, nice forums you have here.
Anyway I've started to learn python, today infact, as I've heard its a good language to learn, I have some experience in BASIC and a little in C from using Linux. I was wondering if there was a function in Python that did the same as mid$() in BASIC, I've searched for tutorials on string manipulation etc, but could not find anything on this function. Thanks. Last edited by acidrock; Aug 23rd, 2005 at 6:48 AM. |
|
|
|
|
|
#2 |
|
Expert Programmer
|
I have no experiance in BASIC, so please explain what the mid$() function does, then i can help you out.
__________________
Join us at #programmingforums @ irc.freenode.net! My software never has bugs. It just develops random features.
|
|
|
|
|
|
#3 |
|
Expert Programmer
|
Ok, i searched google and i didn't find much, from what i found i think that mid$() finds the length of a string.
In Python we have the len() function. Example 1 >>> len("hello")
5>>> variable = "hello" >>>len(variable) 5
__________________
Join us at #programmingforums @ irc.freenode.net! My software never has bugs. It just develops random features.
|
|
|
|
|
|
#4 |
|
Programmer
Join Date: Feb 2005
Posts: 54
Rep Power: 4
![]() |
I think the mid function returns a part of a string. In python, you can consider a string as a list of characters and use the [] notation to get slices. See this tutorial on Python string handling or some simple code:
>>> s = "Hello World!" >>> s[0] 'H' >>> s[0:5] 'Hello' >>> s[:5] 'Hello' >>> s[6:13] 'World!' >>> s[6:] 'World!' >>> s[-1] '!' |
|
|
|
|
|
#5 | |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
Quote:
returns a substring of a string SubStr$ = MID$("abcdefg",3,4)
' Result: SubStr$ will equal "cdef"
SubStr$ = MID$("abcdefg",2)
' Result: SubStr$ will equal "bcdefg"
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
|
#6 |
|
Expert Programmer
|
Ok, so my examples are correct to what he wants.
Thanks Dietrich for clearing that up.
__________________
Join us at #programmingforums @ irc.freenode.net! My software never has bugs. It just develops random features.
|
|
|
|
|
|
#7 |
|
Newbie
Join Date: Aug 2005
Posts: 2
Rep Power: 0
![]() |
That's helped alot, thanks guys.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|