List and tuple operations. PY

Source: Internet
Author: User

Magicians = ['Alice','David','Carolina']#For Loop Operation forMagicianinchMagicians:#do not omit the colon    Print(magician)Print(Magician.title () +', that is a great trick')    Print("I can ' t wait to see your next trick,"+ magician.title () +". \ n")    Print('Thank You,everyone. That is a great magic show!') forValueinchRange (1,5):#using the Range function    Print(value) numbers= List (range (1,6))Print(numbers) even_numbers= List (range (2,11,2))Print(even_numbers) Squares=[] forValueinchRange (1,11): Square= Value**2squares.append (square)Print(squares) Squares= [value**2 forValueinchRange (1,11)]Print(squares) digits= [1,2,3,4,5,6,7,8,9,0]#Simple Statistical calculationPrint(min (digits))Print(max (digits))Print(sum (digits)) Players= ['Charles','Martina','Michael','Florence','Eli']#slicesPrint(Players[0:3])Print(Players[1:4])Print(Players[:3])Print(players[2:])Print(players[-3:]) Players= ['Charles','Martina','Michael','Florence','Eli']Print("Here is the first three players on my team:")#For loop traversal slices forPlayerinchPlayers[:3]:    Print(Player.title ()) My_foods= ['Pizza','Falafel','Carrot Cake',]friend_foods=My_foods[:]my_foods.append ('Cannali') Friend_foods.append ('Ice Creame')Print('My favourate Foods is:')Print(my_foods)Print("\nmy friend ' s favourate Foods is:")Print(friend_foods)Print("The first three iteams in the list is:")Print(My_foods[0:4]) Dimensions= (200,5)#traversing tuples all valuesPrint(Dimensions[0])Print(dimensions[1]) forDimensioninchDimensions:Print(dimension) dimension= (200,50)#Modifying tuple variablesPrint("Original Dimensions:") forDimensioninchDimensions:Print(dimension) dimensions= (400,10)Print("\nmodified Dimensions:") forDimensioninchDimensions:Print(dimension)

List and tuple operations. PY

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.