By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,822 Members | 1,008 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,822 IT Pros & Developers. It's quick & easy.

get input

P: 1
how to get multiple values in array on python
example
for(i=1;i<=3;i++)
scanf("%d",&a[i]);

how to do this action in python
Feb 17 '12 #1
Share this Question
Share on Google+
2 Replies

Smygis
100+
P: 126
Not sure what exactly that action does since I do not program in C so here are what I guess it does:
Expand|Select|Wrap|Line Numbers
  1. a = []
  2. for i in range(1,4):
  3.     a.append(i)
  4.  
  5.  
  6. print a
  7. >>> [1, 2, 3]
  8.  
Feb 17 '12 #2

bvdet
Expert Mod 2.5K+
P: 2,851
As a list comprehension:
Expand|Select|Wrap|Line Numbers
  1. >>> a = [i for i in range(1,4)]
  2. >>> a
  3. [1, 2, 3]
  4. >>> 
Feb 18 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.