Python learning notes enumerate () and range (len) usage and assignment subtotal, pythonenumerate

Source: Internet
Author: User

Python learning notes enumerate () and range (len) usage and assignment subtotal, pythonenumerate

#! /Uer/bin/env python # _ * _ coding: UTF-8 _ * _ # format 1a = 'abc' for I in range (len ()): print a [I], '(% d)' % I

A (0)
B (1)
C (2)

# Format 2for A, I in enumerate ('abc'): print I,

A 0
B 1
C 2

# Format 2.1b = raw_input ('wartyouname: ') for I, j in enumerate (B): print B [I],' (% d) '% I

Wartyouname: ssdf
S (0)
S (1)
D (2)
F (3)

 

#! /Uer/bin/env python # _ * _ coding: UTF-8 _ * _ who = 'kingfei' what = 'ni 'print 'We are the', who, 'Who say ', what, whatprint' We are the % s who say % s' % (who, (what + '') * 4) # note the code 'space'

Output:

We are the kingfei who say NI
We are the kingfei who say NI

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.