Can also be official topic
Anyways, I'm learning python from learnpython.org and I admit it's the best programming language I've tried so far! (Excluding Scratch obviously )
I'm kinda stuck with the strings and stuff.
What has %s and %d got to do with anything?
Last edited by jji7skyline (2012-04-12 19:58:44)
Offline
There is a python official topic created by nickbrickmaster a while back. I'll try and find the link.
EDIT: Here it is.
Last edited by samtwheels (2012-04-12 20:20:51)
Offline
samtwheels wrote:
There is a python official topic created by nickbrickmaster a while back. I'll try and find the link.
EDIT: Here it is.
There seems to be lots of python official topics
Offline
jji7skyline wrote:
samtwheels wrote:
There is a python official topic created by nickbrickmaster a while back. I'll try and find the link.
EDIT: Here it is.There seems to be lots of python official topics
There's this one, the one I made in misc, and the one above.
Offline
Python's great. You knew I would post here.
I think either %s or %d are used like this:
print("Your name is %s.", "Matt")
Offline
I was just messing around with it.
Offline
I got it a couple of days ago (along with about five others), but I haven't even opened it yet.
Offline
The way that things like %s work, is you type %s somewhere in your string, and then after your closing quote you say % followed by what you want to replace the %s with. For example, you could say print("Hello %s!" % "World"), and you would get "Hello World!". The letter is for the type. %s is string, %d is double (or decimal number), and I think that %i is integer (whole number). Anyway, yeah, it's great.
Offline
%s is for when you want the value to be interpreted as a (s)tring, and %d is for when you want the value to be interpreted as a (d)ecimal integer.
Here's some examples:
>>> print('Hello %s' % ('Steve'))
Hello Steve
>>> print('Hello %s' % ('3.14'))
Hello 3.14
>>> print('Hello %s' % (3.14))
Hello 3.14
>>> print('Hello %d' % (3.14))
Hello 3
>>> print('Hello %d' % ('Steve'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: %d format: a number is required, not str
>>>
Have you tried "Invent Your Own Computer Games with Python" at http://inventwithpython.com?
Offline
maxskywalker wrote:
The way that things like %s work, is you type %s somewhere in your string, and then after your closing quote you say % followed by what you want to replace the %s with. For example, you could say print("Hello %s!" % "World"), and you would get "Hello World!". The letter is for the type. %s is string, %d is double (or decimal number), and I think that %i is integer (whole number). Anyway, yeah, it's great.
Ah cool. Thanks. I should continue learning it
Offline
jji7skyline wrote:
maxskywalker wrote:
The way that things like %s work, is you type %s somewhere in your string, and then after your closing quote you say % followed by what you want to replace the %s with. For example, you could say print("Hello %s!" % "World"), and you would get "Hello World!". The letter is for the type. %s is string, %d is double (or decimal number), and I think that %i is integer (whole number). Anyway, yeah, it's great.
Ah cool. Thanks. I should continue learning it
Did it really take you that long to read this? lol
Offline
Well. this is a duplicate too. So, close this one and use this one?
Last edited by CheeseMunchy (2012-07-18 23:13:02)
Offline
samtwheels wrote:
There is a python official topic created by nickbrickmaster a while back. I'll try and find the link.
EDIT: Here it is.
Since this is a duplicate, I'll close it. Remember: the Search button really helps prevent duplicates
Offline