Hi! I am new to Python. How to print number+string+array?

Recommended Answers

All 8 Replies

Can't find anything about it there...

Off course python doc has info about this.
This is very basic off any language.

You can look at this.

i = 55
print i
print(type(i))  

s = 'hello'
print s
print(type(s)) 

l = [1, 2, 3]
print l
print(type(l))  

print('string say %s i am an integer %d this is a list %s' % (s, i, l))

'''-->Out
55
<type 'int'>
hello
<type 'str'>
[1, 2, 3]
<type 'list'>
string say hello i am an integer 55 this is a list [1, 2, 3]
'''

I know about types and stuff, I can do Actionscript 2, JavaScript and php. But I did not know about the %l, only about %d and %f.
But this does not work:

abc=[1,2,6,2,4,2,4,6,3,43,6]
print 'hey%l'%abc

I don't know why, because I can't see the error because when it happens, the window automatcally closes.

EDIT: Not with %s either.

IDLE 2.6.5      
>>> abc = [1,2,6,2,4,2,4,6,3,43,6]
>>> print 'hey%l'%abc

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    print 'hey%l'%abc
ValueError: incomplete format
>>> print 'hey %s' % abc
hey [1, 2, 6, 2, 4, 2, 4, 6, 3, 43, 6]
>>>

hm
It works in Python Shell, but when I try to make a .py file, it just don't work

Here are all my code:

import time
abc = [1,2,6,2,4,2,4,6,3,43,6]
print 'hey%s' % abc
time.sleep(10000000)

time.sleep(10000000)is a vey long time and will give an error message.
OverflowError: sleep length is too large

time.sleep(5) #wait for 5sec
You can try this

import time
abc = [1,2,6,2,4,2,4,6,3,43,6]
print 'hey%s' % abc
time.sleep(5)
print 'What not again %s' % abc

The thing is that as soon as the code stops, the window is crossed out.
So I need to write at the end:

while True: pass

or

time.sleep(x)

But yeah it works when I say time.sleep(100) instead

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.