text stringlengths 1 3.55k | source stringlengths 24 207 | emb listlengths 1.02k 1.02k |
|---|---|---|
6. 7 chapter summary highlights from this chapter include : • functions are named blocks of code that perform tasks when called and make programs more organized and optimized. • control flow is the sequence of program execution. control flow moves between calling code and function code when a function is called. • vari... | openstax_introduction_to_python_programming_-_web | [
0.0291157029569149,
0.006777380593121052,
-0.002423434518277645,
-0.02477252297103405,
-0.03155602887272835,
0.0063563501462340355,
-0.008190212771296501,
0.023447105661034584,
-0.03525369241833687,
0.03169678524136543,
0.03760528564453125,
0.013985502533614635,
-0.002347557805478573,
-0.0... |
. 2 chapter 6 reference. 6. 7 • chapter summary 171 construct description keyword arguments def function _ name ( parameter _ 1, parameter _ 2 ) : # function body function _ name ( parameter _ 2 = 5, parameter _ 1 = 2 ) default parameter value def function _ name ( parameter _ 1 = 100 ) : # function body table 6. 2 cha... | openstax_introduction_to_python_programming_-_web | [
0.029968589544296265,
0.004360625520348549,
0.0308692529797554,
-0.005181139335036278,
-0.033306434750556946,
-0.0018109743250533938,
-0.003632999025285244,
0.047565359622240067,
-0.023077500984072685,
0.0536346361041069,
0.05926884710788727,
-0.0017415047623217106,
0.007646897342056036,
0... |
7. 6 chapter summary introduction as programs get longer and more complex, organizing the code into modules is helpful. this chapter shows how to define, import, and find new modules. python's standard library ( https : / / openstax. org / r / 100pythlibrary ) provides over 200 built - in modules ( https : / / openstax... | openstax_introduction_to_python_programming_-_web | [
0.05108536034822464,
0.020060613751411438,
-0.03682078793644905,
-0.017032550647854805,
0.013664928264915943,
-0.0108038866892457,
0.012829729355871677,
0.024371972307562828,
-0.024211246520280838,
0.056827839463949203,
0.009119904600083828,
0.0445333756506443,
0.014008620753884315,
-0.000... |
7. 1 module basics learning objectives by the end of this section you should be able to • write a module that consists only of function definitions. • import the module and use the functions in a program. defining a module modules are defined by putting code in a. py file. the area module below is in a file named area.... | openstax_introduction_to_python_programming_-_web | [
0.0554681234061718,
0.026310628280043602,
0.0021724156104028225,
-0.01746644824743271,
-0.03816117346286774,
-0.021914925426244736,
0.03259876370429993,
-0.007290705107152462,
-0.020871177315711975,
0.06797972321510315,
0.0407203808426857,
0.02156824804842472,
-0.0070036971010267735,
0.025... |
" return math. pi * radius * ( radius + math. hypot ( height, radius ) ) def sphere ( radius ) : " " " gets the surface area of a sphere. " " " return 4 * math. pi * radius * * 2 concepts in practice defining a module 1. how many functions are defined in the area module? a. 6 b. 10 c. 49 2. what would be the result of ... | openstax_introduction_to_python_programming_-_web | [
0.044667359441518784,
-0.002161758253350854,
-0.025715360417962074,
-0.023015925660729408,
-0.04651099815964699,
0.0001633689971640706,
0.021689951419830322,
0.00283039384521544,
0.0009745455463416874,
0.055566903203725815,
0.031716302037239075,
0.025261009112000465,
-0.02914719469845295,
... |
7. 1 • module basics 175 import area print ( " area of a basketball court : ", area. rectangle ( 94, 50 ) ) print ( " area of a circus ring : ", area. circle ( 21 ) ) the output is : area of a basketball court : 4700 area of a circus ring : 1385. 4423602330987 checkpoint importing area in a python shell access multimed... | openstax_introduction_to_python_programming_-_web | [
0.04349297657608986,
0.022796567529439926,
0.004545361269265413,
0.015110567212104797,
-0.03542047366499901,
-0.015367166139185429,
0.0069286213256418705,
-0.005721706431359053,
-0.033422816544771194,
0.09639134258031845,
0.019359562546014786,
0.035212934017181396,
-0.005010784603655338,
-... |
* 1. 60934. each function should include a docstring as the first line. a docstring for the module has been provided for you. the module should not do anything except define functions. when you click the " run " button, the module should run without error. no output should be displayed. access multimedia content ( http... | openstax_introduction_to_python_programming_-_web | [
0.010779069736599922,
0.013006477616727352,
-0.0042853099294006824,
0.026305636391043663,
-0.042019426822662354,
-0.015926776453852654,
-0.012030425481498241,
-0.01391794066876173,
-0.001465683919377625,
0.0646631047129631,
-0.019090993329882622,
0.03476224094629288,
0.02372446469962597,
-... |
7. 2 • importing names 177 the from keyword specific functions in a module can be imported using the from keyword : from area import triangle, cylinder these functions can be called directly, without referring to the module : print ( triangle ( 1, 2 ) ) print ( cylinder ( 3, 4 ) ) exploring further as shown below, the ... | openstax_introduction_to_python_programming_-_web | [
0.026069918647408485,
0.01065257377922535,
0.010297773405909538,
0.017422091215848923,
-0.019520558416843414,
-0.03221788629889488,
-0.01742921583354473,
0.004267836920917034,
-0.016806745901703835,
0.07834482192993164,
0.027484949678182602,
0.00788453035056591,
-0.0012834047665819526,
0.0... |
collisions because a module. name format would be used. this is a tradeoff the programmer must consider. checkpoint module and function names access multimedia content ( https : / / openstax. org / books / introduction - python - programming / pages / 7 - 2 - importing - names ) concepts in practice name collisions 4. ... | openstax_introduction_to_python_programming_-_web | [
0.005491324700415134,
-0.013537626713514328,
0.02745719812810421,
0.012377187609672546,
-0.01206674613058567,
-0.03352024778723717,
0.019567852839827538,
-0.009801827371120453,
0.004630239214748144,
0.06621940433979034,
-0.0005426119896583259,
0.02110276371240616,
0.028555646538734436,
-0.... |
7. 2 • importing names 179 6 7 hello ( ) 8 hello ( " chris " ) a. line 4 b. line 7 c. line 8 exploring further if a name is defined, imported, or assigned multiple times, python uses the most recent definition. other languages allow multiple functions to have the same name if the parameters are different. this feature,... | openstax_introduction_to_python_programming_-_web | [
0.031439658254384995,
0.012210488319396973,
0.022864971309900284,
0.005827032960951328,
-0.01667633466422558,
-0.01130350586026907,
0.004803705494850874,
0.00686229532584548,
0.007473973091691732,
0.03297349438071251,
0.017120173200964928,
0.014265069738030434,
-0.007070715073496103,
-0.00... |
7. 3 top - level code learning objectives by the end of this section you should be able to 180 7 • modules access for free at openstax. org • identify code that will run as a side effect of importing. • explain the purpose of if _ _ name _ _ = = " _ _ main _ _ ". side effects modules define functions and constants to b... | openstax_introduction_to_python_programming_-_web | [
-0.009671987034380436,
-0.004063551779836416,
0.005706670694053173,
-0.03559604287147522,
-0.02453199401497841,
-0.0045002964325249195,
0.00047055818140506744,
-0.004685199819505215,
-0.019046815112233162,
0.05313129723072052,
-0.00033481884747743607,
0.04915010556578636,
0.01107585150748491... |
7. 3 • top - level code 181 print ( f " nice to meet you, { name }! " ) live = input ( " where do you live? " ) print ( f " { live } is a great place. " ) a. true b. false using _ _ name _ _ python modules often include the statement if _ _ name _ _ = = " _ _ main _ _ " to prevent side effects. this statement is true w... | openstax_introduction_to_python_programming_-_web | [
0.0001395796425640583,
-0.007878763601183891,
0.01652008667588234,
-0.004556021187454462,
-0.022076094523072243,
-0.012304617092013359,
-0.0015530887758359313,
0.008046257309615612,
-0.014857725240290165,
0.05387630686163902,
0.01215877290815115,
0.004270288627594709,
0.03446749597787857,
... |
' s docstring ) and _ _ file _ _ ( the module's filename ). try it side effects this exercise is a continuation of the " missing imports " exercise. previously, you added missing import statements to the top of the program. now, modify the program to prevent side effects when importing the program as a module : 1. add ... | openstax_introduction_to_python_programming_-_web | [
-0.010482223704457283,
0.00811506062746048,
0.011472671292722225,
0.0238778218626976,
-0.04079652950167656,
-0.020228024572134018,
0.008769306354224682,
0.007187332957983017,
-0.015419662930071354,
0.07536374032497406,
-0.013837545178830624,
0.020655712112784386,
0.014585541561245918,
-0.0... |
/ openstax. org / books / introduction - python - programming / pages / 7 - 3 - top - level - code ) | openstax_introduction_to_python_programming_-_web | [
0.012707928195595741,
0.0020298899617046118,
0.008881596848368645,
-0.022763751447200775,
-0.0042280880734324455,
-0.041800156235694885,
-0.010231186635792255,
-0.012783023528754711,
-0.006560704205185175,
0.0498918816447258,
-0.007541246246546507,
0.032944872975349426,
0.022951722145080566,... |
7. 4 the help function learning objectives by the end of this section you should be able to • use the help ( ) function to explore a module's contents. • identify portions of code included in the documentation. colors on websites this section introduces an example module for working with html colors ( https : / / opens... | openstax_introduction_to_python_programming_-_web | [
0.029605593532323837,
-0.016717182472348213,
0.01981407403945923,
0.028359929099678993,
-0.06437166780233383,
0.004339220002293587,
0.0010719813872128725,
-0.010325681418180466,
0.0040587433613836765,
0.09365156292915344,
0.009582919999957085,
0.026426702737808228,
0.023625152185559273,
0.... |
color is lighter? a. # ffa500 ( orange ) b. # 008000 ( green ) example colors module a module for working with html color codes would be helpful to graphic designers and web developers. the following python code is in a file named colors. py. • line 1 is the docstring for the module. • lines 3 – 16 assign variables for... | openstax_introduction_to_python_programming_-_web | [
0.04107559472322464,
-0.0350060760974884,
0.005101171787828207,
-0.0016369158402085304,
-0.059502117335796356,
-0.01702696830034256,
0.025081554427742958,
0.0002467725716996938,
-0.023310314863920212,
0.08133654296398163,
0.003302948782220483,
0.010380472987890244,
0.03538241609930992,
0.0... |
7. 4 • the help function 185 " " " converts an integer to an 8 - bit ( 2 - digit ) hexadecimal string. " " " if value < = 0 : return " 00 " if value > = 255 : return " ff " return format ( value, " 02x " ) def tohex ( r, g, b ) : " " " formats red, green, and blue integers as a color in hexadecimal. " " " return " # " ... | openstax_introduction_to_python_programming_-_web | [
0.020329676568508148,
-0.02343570999801159,
0.014273680746555328,
0.00684380391612649,
-0.04832666739821434,
-0.018945666030049324,
0.0025822846218943596,
-0.010845312848687172,
-0.022932402789592743,
0.11067778617143631,
0.019894002005457878,
-0.00869995728135109,
0.016012748703360558,
0.... |
would return a darker shade of blue? a. darken ( blue ) b. colors. darken ( blue ) c. colors. darken ( colors. blue ) 6. what symbol indicates that a function is not intended to be called by other modules? a. underscore ( _ ) b. number sign ( # ) c. colon ( : ) 186 7 • modules access for free at openstax. org module do... | openstax_introduction_to_python_programming_-_web | [
0.025369327515363693,
-0.03794394060969353,
0.0023350727278739214,
-0.009709501639008522,
-0.03580595552921295,
-0.015335560776293278,
0.013140027411282063,
0.018081383779644966,
-0.021492959931492805,
0.09659191966056824,
0.01386310439556837,
0.03273216262459755,
0.02600511722266674,
0.01... |
7. 4 • the help function 187 colors - functions for working with color names and hex / rgb values. functions darken ( color ) decreases the red, green, and blue values of a color by 32 each. lighten ( color ) increases the red, green, and blue values of a color by 32 each. tohex ( r, g, b ) formats red, green, and blue... | openstax_introduction_to_python_programming_-_web | [
0.012784095481038094,
-0.016482017934322357,
0.00872673001140356,
-0.001782683772034943,
-0.05309237167239189,
-0.01930970884859562,
-0.005330715328454971,
0.0055716875940561295,
-0.024405980482697487,
0.10158798098564148,
0.00808106828480959,
0.013156536035239697,
0.008266556076705456,
0.... |
) • import statistics • help ( statistics ) many shell environments, including the one on python. org, display the output of help ( ) one page at a time. use the navigation keys on the keyboard ( up / down arrows, page up / down, home / end ) to read the documentation. when you are finished reading, press the q key ( "... | openstax_introduction_to_python_programming_-_web | [
0.036470986902713776,
0.02633731998503208,
-0.00853350292891264,
-0.020477816462516785,
-0.00003737689621630125,
-0.02305774576961994,
-0.018043451011180878,
0.031927671283483505,
0.0009197660256177187,
0.10067670792341232,
-0.007904578931629658,
0.018293917179107666,
-0.020091962069272995,
... |
7. 5 • finding modules 189 built - in modules the python standard library is a collection of built - in functions and modules that support common programming tasks. ex : the math module provides functions like sqrt ( ) and constants like pi. python's official documentation includes a library reference ( https : / / ope... | openstax_introduction_to_python_programming_-_web | [
0.04691316559910774,
0.013929861597716808,
-0.038726016879081726,
-0.028098395094275475,
-0.012681014835834503,
0.01996595971286297,
-0.013609213754534721,
0.003382921451702714,
-0.01924852281808853,
0.07281051576137543,
-0.0054364581592381,
0.015203014016151428,
0.020022153854370117,
-0.0... |
available at pypi. org ( https : / / openstax. org / r / 100pypi ), is the official third - party software library for python. the abbreviation " pypi " is pronounced like pie pea eye ( in contrast to pypy ( https : / / openstax. org / r / 100pypy ), a different project ). pypi allows anyone to develop and share module... | openstax_introduction_to_python_programming_-_web | [
0.04996001720428467,
0.025566110387444496,
-0.041909828782081604,
-0.0039321961812675,
-0.009488479234278202,
0.0022795493714511395,
-0.024561172351241112,
-0.011985189281404018,
0.010972135700285435,
0.052072107791900635,
-0.04949256032705307,
-0.05050633102655411,
0.02383267879486084,
-0... |
7. 5 • finding modules 191 module description pytest full - featured testing tool and unit test framework. requests elegant http library for connecting to web servers. scikit - learn simple, efficient tools for predictive data analysis. scipy fundamental algorithms for scientific computing. scrapy crawl websites and sc... | openstax_introduction_to_python_programming_-_web | [
0.06946738064289093,
0.016522742807865143,
-0.031268250197172165,
0.0005802484811283648,
-0.03753940388560295,
0.004607358016073704,
-0.04212389886379242,
-0.0045160818845033646,
0.012152411043643951,
0.07746139168739319,
-0.026059679687023163,
-0.019222524017095566,
0.0553659088909626,
0.... |
exercise, refer to the following examples from the datetime module documentation : • examples of usage : date ( https : / / openstax. org / r / 100dateexamples ) • examples of usage : timedelta ( https : / / openstax. org / r / 100timedeltaex ) write a program that creates a date object representing your birthday. then... | openstax_introduction_to_python_programming_-_web | [
0.03298422321677208,
0.029700489714741707,
-0.031197164207696915,
-0.010035729967057705,
-0.021618962287902832,
-0.004031897522509098,
0.012998686172068119,
-0.013964943587779999,
0.01033825520426035,
0.09689034521579742,
-0.02945820987224579,
-0.025683574378490448,
0.04440370947122574,
0.... |
7. 5 • finding modules 193 notice how leap years are included in the calculation. february 29th occurs four times between birth and today. therefore, the user is not only 15 years old, but 15 years and 4 days old. many commonly used modules from pypi, including arrow, are installed in the python shell at python. org / ... | openstax_introduction_to_python_programming_-_web | [
0.035696301609277725,
0.05478791147470474,
-0.023795897141098976,
-0.01440143771469593,
-0.020442193374037743,
-0.000017927683074958622,
0.005382216069847345,
0.009556935168802738,
0.006604423280805349,
0.07202576100826263,
-0.010813276283442974,
-0.046916525810956955,
0.01102574821561575,
... |
7. 6 chapter summary highlights from this chapter include : • programs can be organized into multiple. py files ( modules ). the import keyword allows a program to use functions defined in another. py file. • the from keyword can be used to import specific functions from a module. however, programs should avoid importi... | openstax_introduction_to_python_programming_-_web | [
0.05165019631385803,
0.008096005767583847,
-0.019625885412096977,
0.005607077851891518,
-0.0068079326301813126,
0.00205998751334846,
-0.012816148810088634,
0.022302798926830292,
-0.006238569505512714,
0.08857753872871399,
0.00269823195412755,
0.01664598286151886,
0.006303995382040739,
-0.0... |
module's file name. help ( function _ name ) shows the docstring for the given function. date ( 2023, 2, 14 ) creates a date object representing february 14, 2023. requires : from datetime import date. table 7. 3 chapter 7 reference. 7. 6 • chapter summary 195 196 7 • modules access for free at openstax. org figure 8. ... | openstax_introduction_to_python_programming_-_web | [
0.04038522019982338,
0.0005635286215692759,
0.008777487091720104,
-0.009126095101237297,
-0.044070273637771606,
-0.026337264105677605,
0.023258013650774956,
0.0020778237376362085,
0.01846044510602951,
0.09318063408136368,
0.007630534935742617,
-0.010673701763153076,
0.029777614399790764,
0... |
8. 1 string operations learning objectives by the end of this section you should be able to • compare strings using logical and membership operators. • use lower ( ) and upper ( ) string methods to convert string values to lowercase and uppercase characters. string comparison string values can be compared using logical... | openstax_introduction_to_python_programming_-_web | [
0.012542449869215488,
-0.018752818927168846,
0.05307814106345177,
-0.026054980233311653,
-0.04359251633286476,
-0.030121324583888054,
0.029096204787492752,
-0.029468322172760963,
-0.02155793458223343,
0.07837670296430588,
0.005251454655081034,
0.03305565565824509,
0.01715872623026371,
-0.0... |
" ), and the result of checking whether the two are not the same evaluates to true. in checks whether the second operand contains the first operand. " a " in " bc " false since string " bc " does not contain string " a ", the output of " a " in " bc " evaluates to false. not in checks whether the second operand does no... | openstax_introduction_to_python_programming_-_web | [
0.012983614578843117,
-0.022112788632512093,
0.014009661972522736,
-0.03278226777911186,
-0.02335400879383087,
-0.04846658557653427,
0.00714079337194562,
-0.019292859360575676,
-0.01946992427110672,
0.08259802311658859,
0.001379805733449757,
-0.0001966473791981116,
-0.0000030597309432778275,... |
##case characters print ( x. upper ( ) ) the above code's output is : apples apples concepts in practice using lower ( ) and upper ( ) 4. what is the output of " abba ". lower ( )? a. abba b. abba c. abba 5. what is the output of " abba ". upper ( )? a. abba | openstax_introduction_to_python_programming_-_web | [
0.026784300804138184,
-0.02985035814344883,
0.020810173824429512,
-0.029156776145100594,
-0.0006585278897546232,
-0.07589801400899887,
0.018790116533637047,
-0.02296750247478485,
-0.00507664680480957,
0.04970364645123482,
0.018791375681757927,
0.03794129192829132,
-0.016391053795814514,
-0... |
8. 1 • string operations 199 b. abba c. abba d. abba 6. what is the output of ( " a ". upper ( ) = = " a " )? a. true b. false try it number of characters in the string a string variable, s _ input, is defined. use lower ( ) and upper ( ) to convert the string to lowercase and uppercase, and print the results in the ou... | openstax_introduction_to_python_programming_-_web | [
0.006556239910423756,
-0.016215721145272255,
0.00983375683426857,
-0.025203220546245575,
-0.007761620916426182,
-0.03446047753095627,
0.016233494505286217,
-0.013646417297422886,
0.010382089763879776,
0.06455931812524796,
0.031863778829574585,
0.004689898807555437,
-0.02463110163807869,
-0... |
8. 2 string slicing learning objectives by the end of this section you should be able to • use string indexing to access characters in the string. • use string slicing to get a substring from a string. • identify immutability characteristics of strings. string indexing a string is a type of sequence. a string is made u... | openstax_introduction_to_python_programming_-_web | [
0.005405247677117586,
0.0011093635112047195,
0.016872214153409004,
0.011969443410634995,
-0.00759332487359643,
-0.02404182218015194,
0.02120908349752426,
-0.0094469478353858,
-0.019141701981425285,
0.09182935208082199,
0.0030947555787861347,
-0.026253212243318558,
0.005290048196911812,
-0.... |
string slicing operator can be used. when [ a : b ] is used with the name of a string variable, a sequence of characters starting from index a ( inclusive ) up to index b ( exclusive ) is returned. both a and b are optional. if a or b are not provided, the default values are 0 and len ( string ), respectively. example ... | openstax_introduction_to_python_programming_-_web | [
0.010433359071612358,
0.010248830541968346,
0.006768499035388231,
-0.019883714616298676,
-0.03837751969695091,
-0.012032893486320972,
0.025935547426342964,
0.013259812258183956,
-0.002902462612837553,
0.07055686414241791,
0.030238794162869453,
-0.033934980630874634,
0.006477269344031811,
-... |
8. 2 • string slicing 201 the above code's output is : 46 example 8. 3 getting the hour consider a time value is given as " hh : mm " with " hh " representing the hour and " mm " representing the minutes. to retrieve only the string's hour portion, the following code can be used : time _ string = " 14 : 50 " hour = tim... | openstax_introduction_to_python_programming_-_web | [
0.024143531918525696,
0.04219719022512436,
-0.022980237379670143,
-0.003580446820706129,
-0.033975742757320404,
-0.05173549801111221,
-0.02502855472266674,
-0.02041665092110634,
0.02156589925289154,
0.05532831698656082,
0.012273048982024193,
-0.006134433671832085,
0.02269691973924637,
-0.0... |
to character " * " in a new string? a. x = " string " x [ 0 ] = " * " b. x = " string " x = " * " + x [ 1 : ] c. x = " string " x = " * " + x 8. what type of error will result from the following code? string _ variable = " example " string _ variable [ - 1 ] = " " a. typeerror b. indexerror c. nameerror 9. what is the ... | openstax_introduction_to_python_programming_-_web | [
0.02650666981935501,
-0.016906751319766045,
0.04494145140051842,
-0.026167701929807663,
-0.011193502694368362,
-0.06976105272769928,
0.061815325170755386,
0.004122704733163118,
0.003055780427530408,
0.06606138497591019,
0.024226900190114975,
0.013052606955170631,
0.013743231073021889,
-0.0... |
8. 2 • string slicing 203 a. typeerror b. m c. o try it changing the greeting message given the string " hello my fellow classmates " containing a greeting message, print the first word by getting the beginning of the string up to ( and including ) the 5th character. change the first word in the string to " hi " instea... | openstax_introduction_to_python_programming_-_web | [
0.02194214053452015,
0.008122389204800129,
0.009532700292766094,
0.03567127883434296,
-0.029006944969296455,
-0.03935278579592705,
-0.007349987048655748,
-0.006071928888559341,
0.008718754164874554,
0.04183231294155121,
0.010685031302273273,
-0.0066057732328772545,
0.006771519314497709,
-0... |
8. 3 searching / testing strings learning objectives by the end of this section you should be able to • use the in operator to identify whether a given string contains a substring. • call the count ( ) method to count the number of substrings in a given string. • search a string to find a substring using the find ( ) m... | openstax_introduction_to_python_programming_-_web | [
0.02520209737122059,
0.026660356670618057,
0.004473244771361351,
0.001895700115710497,
-0.007561057340353727,
-0.01348956860601902,
-0.011726528406143188,
-0.030549488961696625,
0.01550700981169939,
0.09440992772579193,
0.015514425933361053,
0.0006215417524799705,
0.013365445658564568,
-0.... |
? | openstax_introduction_to_python_programming_-_web | [
0.002933684503659606,
0.008792364038527012,
0.03403783589601517,
-0.03241798281669617,
0.015143533237278461,
-0.009980157017707825,
0.006941614206880331,
0.03107253834605217,
0.033378105610609055,
0.05102672055363655,
0.01008778065443039,
0.019181007519364357,
-0.00205637002363801,
0.00300... |
8. 3 • searching / testing strings 205 for c in " string " : print ( c, end = " " ) a. string b. s t r i n g c. s t r i n g 5. what is the output of the following code? count = 0 for c in " abca " : if c = = " a " : count + = 1 print ( count ) a. 0 b. 1 c. 2 6. what is the output of the following code? word = " cab " f... | openstax_introduction_to_python_programming_-_web | [
0.013858404941856861,
0.001259773736819625,
0.016527246683835983,
0.0008254154236055911,
0.0017865723930299282,
-0.029585834592580795,
-0.025273103266954422,
-0.02479206584393978,
0.010753253474831581,
0.06995344907045364,
0.01094642374664545,
-0.021363303065299988,
-0.009737935848534107,
... |
( ) method returns the index of the first occurrence of a substring in a given string. if the substring does not exist in the given string, the value of - 1 is returned. checkpoint finding the first index of a substring access multimedia content ( https : / / openstax. org / books / introduction - python - programming ... | openstax_introduction_to_python_programming_-_web | [
0.007579525467008352,
0.009194653481245041,
-0.00773997837677598,
-0.004291564226150513,
-0.00008989915659185499,
-0.04095130041241646,
-0.04078167676925659,
0.017029782757163048,
0.026068279519677162,
0.07675487548112869,
-0.00007868358079576865,
-0.03721673786640167,
0.00020657232380472124... |
8. 3 • searching / testing strings 207 a. 0 b. - 1 c. valueerror 12. what is the output of " b ". find ( " banana " )? a. - 1 b. 0 c. valueerror index ( ) the index ( ) method performs similarly to the find ( ) method in which the method returns the index of the first occurrence of a substring in a given string. the in... | openstax_introduction_to_python_programming_-_web | [
-0.014012088999152184,
0.029853912070393562,
0.0006362870917655528,
-0.003926423378288746,
-0.016051340848207474,
-0.021428870037198067,
-0.03179563954472542,
-0.0006296217907220125,
0.01952158287167549,
0.08673524856567383,
-0.009006479755043983,
-0.012978934682905674,
-0.007461695000529289... |
string with all spaces removed. input : " this is great " prints : 2 thisisgreat access multimedia content ( https : / / openstax. org / books / introduction - python - programming / pages / 8 - 3 - searchingtesting - strings ) 8. 4 string formatting learning objectives by the end of this section you should be able to ... | openstax_introduction_to_python_programming_-_web | [
0.016089770942926407,
-0.000251172372372821,
0.023064162582159042,
-0.018011856824159622,
-0.038247250020504,
-0.031844839453697205,
0.01872263476252556,
-0.006802089512348175,
0.005765811074525118,
0.08232976496219635,
0.0486181303858757,
0.001809456734918058,
0.002367084613069892,
-0.037... |
8. 4 • string formatting 209 format. the example below shows two string values that use the same template for making requests to different individuals for taking different courses. example 8. 5 string values from the same template dear john, i'd like to take a programming course with prof. potter. dear kishwar, i'd lik... | openstax_introduction_to_python_programming_-_web | [
-0.0050697484984993935,
-0.003752027405425906,
0.04360352084040642,
-0.018695462495088577,
-0.04126783460378647,
-0.030035560950636864,
-0.003195637371391058,
-0.023263363167643547,
0.0030284796375781298,
0.07383877784013748,
0.022198256105184555,
0.007709256839007139,
0.03039924055337906,
... |
. hello ana! 2. what is the output of print ( " { } : { } ". format ( " one ", " 1 " ) )? a. one1 b. one : 1 c. 1 : one 3. what is the output of print ( " { } ". format ( " one ", " two ", " three " ) )? a. one b. two c. onetwothree named replacement fields replacement fields can be tagged with a label, called named re... | openstax_introduction_to_python_programming_-_web | [
0.009019900113344193,
-0.0169589351862669,
0.010645921342074871,
0.010346258990466595,
-0.015323425643146038,
-0.010033267550170422,
-0.0008015841594897211,
-0.019207099452614784,
0.018799301236867905,
0.04908260703086853,
0.03397904336452484,
0.017941482365131378,
0.027987593784928322,
-0... |
8. 4 • string formatting 211 s = " weather in { season } is { temperature } ; very very { temperature }. " print ( s ) print ( s. format ( season = " summer ", temperature = " hot " ) ) print ( s. format ( temperature = " cold ", season = " winter " ) ) the above code's output is : weather in { season } is { temperatur... | openstax_introduction_to_python_programming_-_web | [
0.020192299038171768,
-0.0028546778485178947,
0.030080007389187813,
-0.009991021826863289,
-0.020958656445145607,
-0.008419631980359554,
0.012631506659090519,
0.00587144261226058,
0.005933401640504599,
0.07384565472602844,
0.02846909873187542,
0.017039453610777855,
0.007684497628360987,
-0... |
212 8 • strings access for free at openstax. org home ". numbered replacement fields can use argument's values for multiple replacement fields by using the same argument index. the example below illustrates how an argument is used for more than one numbered replacement field. example 8. 8 numbered replacement field to ... | openstax_introduction_to_python_programming_-_web | [
0.03428442031145096,
0.004376045893877745,
0.051141493022441864,
0.04064228758215904,
-0.04963221400976181,
-0.004554737824946642,
-0.004586637485772371,
-0.012535826303064823,
-0.0019015992293134332,
0.07518743723630905,
0.056667935103178024,
0.02167326770722866,
-0.00564818549901247,
-0.... |
8. 4 • string formatting 213 formatted table. the field width in string format specification is used to specify the minimum length of the given string. if the string is shorter than the given minimum length, the string will be padded by space characters. a field width is included in the format specification field using... | openstax_introduction_to_python_programming_-_web | [
0.03399671986699104,
-0.03371590003371239,
0.05766637250781059,
0.013249015435576439,
-0.032199323177337646,
0.02973397634923458,
0.03675507381558418,
-0.014263525605201721,
-0.04436015337705612,
0.06829312443733215,
0.03954840078949928,
-0.00039567521889694035,
-0.003210867987945676,
-0.0... |
) print ( template. format ( hex = " # 00ff00 ", name = " green " ) ) # ff0000 red # 00ff00 green table 8. 2 string alignment formatting. concepts in practice specifying field width and alignment 7. what is the output of the following code? template = " { name : 12 } " formatted _ name = template. format ( name = " ali... | openstax_introduction_to_python_programming_-_web | [
0.0020419980864971876,
-0.022287821397185326,
0.03201325237751007,
0.008380460552871227,
-0.031410519033670425,
0.011357289738953114,
0.014797286130487919,
-0.021087517961859703,
-0.03031720593571663,
0.05681435763835907,
0.0214094165712595,
0.0011629770742729306,
-0.0025964691303670406,
0... |
table below summarizes formatting options for modifying numeric values. example output explanation print ( " { :. 7f } ". format ( 0. 9795 ) ) 0. 9795000 the format specification. 7 shows the output must have seven decimal places. the f specification is an identifier of floating - point formatting. print ( " { :. 3f } ... | openstax_introduction_to_python_programming_-_web | [
0.018186835572123528,
-0.023872870951890945,
0.02992451936006546,
-0.005058593582361937,
-0.019345039501786232,
0.0025581696536391973,
0.038554057478904724,
-0.011866368353366852,
-0.03734344244003296,
0.051141224801540375,
0.0306242723017931,
-0.009907393716275692,
0.014433056116104126,
0... |
8. 4 • string formatting 215 example output explanation print ( " { : +. 2f } ". format ( 4 ) ) + 4. 00 the format specification. 2 shows the output must have two decimal places. the f specification is an identifier of floating - point formatting. the + sign before the precision specification adds a sign character to t... | openstax_introduction_to_python_programming_-_web | [
0.00460147624835372,
-0.017622536048293114,
0.04837171360850334,
0.015554524026811123,
-0.0219072625041008,
0.005733322352170944,
0.04577352851629257,
-0.0158714447170496,
-0.047722481191158295,
0.05798603221774101,
0.019176701083779335,
-0.004355934448540211,
0.014456161297857761,
0.02181... |
input : [ 12. 5, 2 ] prints : 012. 50 002 : 00 access multimedia content ( https : / / openstax. org / books / introduction - python - programming / pages / 8 - 4 - string - formatting ) | openstax_introduction_to_python_programming_-_web | [
0.012884771451354027,
0.0036034616641700268,
0.01160249300301075,
0.01784968189895153,
0.0063919140957295895,
-0.04057690501213074,
0.0005678307497873902,
-0.0317954495549202,
0.0098454924300313,
0.07839620113372803,
-0.004452607594430447,
0.014979271218180656,
0.034687742590904236,
-0.056... |
8. 5 splitting / joining strings learning objectives by the end of this section you should be able to • use the split ( ) method to split a string into substrings. • combine objects in a list into a string using join ( ) method. split ( ) a string in python can be broken into substrings given a delimiter. a delimiter i... | openstax_introduction_to_python_programming_-_web | [
0.03850743919610977,
-0.00894142221659422,
0.0008573337108828127,
0.009790061973035336,
-0.04511462524533272,
-0.047442372888326645,
0.0016844847705215216,
0.013988157734274864,
0.03141101077198982,
0.10317493230104446,
-0.005139218643307686,
0.033759381622076035,
-0.01759287528693676,
-0.... |
8. 5 • splitting / joining strings 217 b. [ " 1 ", " 2 ', " 3 " ] c. [ 1, 2, 3 ] 2. what is the output of print ( " a year includes 12 months ". split ( ) )? a. [ " a year includes 12 months " ] b. [ " a ", " year ", " includes ", 12, " months " ] c. [ " a ", " year ", " includes ", " 12 ", " months " ] 3. what is the ... | openstax_introduction_to_python_programming_-_web | [
0.014514308422803879,
-0.012546437792479992,
0.024952929466962814,
0.010618551634252071,
-0.015913406386971474,
-0.05666813254356384,
-0.010864152573049068,
-0.0078005664981901646,
0.03261276334524155,
0.08050563931465149,
-0.016713853925466537,
0.03679492697119713,
0.003584038931876421,
-... |
, learning'] c.'a, beautiful, day, for, learning'5. what is the length of the string " sss ". join ( [ " 1 ", " 2 " ] )? a. 2 218 8 • strings access for free at openstax. org b. 5 c. 8 6. what is the value stored in the variable out? s = [ " 1 ", " 2 " ] out = " ". join ( s ) a. 12 b. " 12 " c. " 1 2 " try it unique an... | openstax_introduction_to_python_programming_-_web | [
0.027463121339678764,
0.01602691039443016,
0.03113224171102047,
0.0346001498401165,
-0.02439272589981556,
-0.04241066426038742,
-0.00995982252061367,
0.012547602877020836,
0.005950255785137415,
0.060683947056531906,
0.018120424821972847,
0.04826854541897774,
-0.0124537143856287,
-0.0428829... |
access multimedia content ( https : / / openstax. org / books / introduction - python - programming / pages / 8. 5 • splitting / joining strings 219 8 - 5 - splittingjoining - strings ) | openstax_introduction_to_python_programming_-_web | [
0.023994915187358856,
0.007338870782405138,
-0.005254525691270828,
0.013618583790957928,
0.012312821112573147,
-0.043232910335063934,
-0.027072099968791008,
0.008936671540141106,
0.03855578228831291,
0.07874004542827606,
0.0037355665117502213,
0.016754578799009323,
0.0322604775428772,
-0.0... |
8. 6 chapter summary highlights from this chapter include : • a string is a sequence of characters. • logical operators can be used to compare two string values. string comparison is done by comparing corresponding ascii values of characters in the order of appearance in the string. • string indexing is used to access ... | openstax_introduction_to_python_programming_-_web | [
0.018297307193279266,
0.006401426624506712,
0.030962813645601273,
-0.010506393387913704,
0.002618025057017803,
-0.032237306237220764,
-0.002306136768311262,
-0.02197512425482273,
0.013804465532302856,
0.09745601564645767,
0.017993971705436707,
0.004999646916985512,
0.0018358093220740557,
-... |
by alabama extension / flickr, public domain chapter outline 9. 1 modifying and iterating lists 9. 2 sorting and reversing lists 9. 3 common list operations 9. 4 nested lists 9. 5 list comprehensions 9. 6 chapter summary introduction programmers often work on collections of data. lists are a useful way of collecting da... | openstax_introduction_to_python_programming_-_web | [
-0.014665537513792515,
-0.011747349984943867,
-0.0111485430970788,
-0.057824116200208664,
-0.0036430545151233673,
0.0040239556692540646,
-0.018900595605373383,
0.0004951943992637098,
0.029710978269577026,
0.09324225783348083,
-0.036440640687942505,
0.039207879453897476,
0.012440877966582775,... |
9. 1 modifying and iterating lists learning objectives by the end of this section you should be able to • modify a list using append ( ), remove ( ), and pop ( ) list operations. • search a list using a for loop. using list operations to modify a list an append ( ) operation is used to add an element to the end of a li... | openstax_introduction_to_python_programming_-_web | [
-0.013897719793021679,
-0.015233742073178291,
0.011047686450183392,
-0.0004835985309910029,
-0.025852398946881294,
-0.03778371587395668,
-0.02953035570681095,
-0.0169865470379591,
0.021301183849573135,
0.09088394790887833,
-0.00933656096458435,
0.0015227533876895905,
0.01381722092628479,
-... |
tae'] ['jamie ','vicky ','deshawn ','tae ','ming'] ['vicky ','deshawn ','tae ','ming'] ['vicky ','deshawn ','tae'] concepts in practice modifying lists 1. which operation can be used to add an element to the end of a list? a. add ( ) b. append ( ) c. pop ( ) 224 9 • lists access for free at openstax. org 2. what is the... | openstax_introduction_to_python_programming_-_web | [
-0.022288555279374123,
-0.02261432819068432,
0.0011304451618343592,
-0.0005178216379135847,
-0.04115540161728859,
-0.03194756433367729,
-0.02394438162446022,
-0.01989074796438217,
-0.00033350783633068204,
0.07759188115596771,
0.0013895853189751506,
0.0304537583142519,
0.00485525606200099,
... |
5 6. what is the output of the code below? for i in range ( 0, len ( my _ list ), 2 ) : print ( my _ list [ i ], end ='' ) a. 2 5 9 b. 2 3 5 7 9 | openstax_introduction_to_python_programming_-_web | [
-0.008306284435093403,
-0.03975744545459747,
0.020980071276426315,
0.0023167605977505445,
0.002176836598664522,
-0.051955752074718475,
0.007823172956705093,
0.011490500532090664,
0.024876125156879425,
0.0769839733839035,
0.0012434690725058317,
0.010537014342844486,
-0.0109550841152668,
-0.... |
9. 1 • modifying and iterating lists 225 c. 2 5 9 try it sports list create a list of sports played on a college campus. the sports to be included are baseball, football, tennis, and table tennis. next, add volleyball to the list. next, remove " football " from the list and add " soccer " to the list. show the list con... | openstax_introduction_to_python_programming_-_web | [
-0.028339920565485954,
0.0034785126335918903,
0.025352466851472855,
0.006905680522322655,
-0.01787903718650341,
0.013055185787379742,
-0.04978546127676964,
-0.008873802609741688,
0.023192469030618668,
0.06950605660676956,
0.010237276554107666,
0.007398005574941635,
0.07143061608076096,
-0.... |
9. 2 sorting and reversing lists learning objectives by the end of this section you should be able to • understand the concept of sorting. • use built - in sort ( ) and reverse ( ) methods. sorting ordering elements in a sequence is often useful. sorting is the task of arranging elements in a sequence in ascending or d... | openstax_introduction_to_python_programming_-_web | [
-0.002349626272916794,
-0.03024911880493164,
-0.015495005995035172,
-0.027120724320411682,
0.005514702294021845,
0.010640467517077923,
-0.005018941592425108,
0.008119289763271809,
-0.007748061791062355,
0.09669091552495956,
-0.012537658214569092,
0.008705532178282738,
-0.0024206803645938635,... |
characters, leading to unexpected results. ex : " a " is ordered before " a " in ascending order but so is " g " ; thus, " gail " comes before " apple ". • the reverse ( ) method reverses the elements in a list. example 9. 2 sorting and reversing lists # setup a list of numbers num _ list = [ 38, 92, 23, 16 ] print ( n... | openstax_introduction_to_python_programming_-_web | [
0.0037687562871724367,
-0.03203732892870903,
-0.013571695424616337,
-0.04048270359635353,
0.011391876265406609,
-0.029798708856105804,
0.0007997325737960637,
0.00004177035589236766,
-0.006624528672546148,
0.09819488972425461,
0.01360831968486309,
0.0027616953011602163,
0.008551434613764286,
... |
9. 2 • sorting and reversing lists 227 # reverse the list dance _ list. reverse ( ) print ( dance _ list ) # sort the list dance _ list. sort ( ) print ( dance _ list ) the above code's output is : [ 38, 92, 23, 16 ] [ 16, 23, 38, 92 ] [ " dabke ", " flamenco ", " hopak ", " kathak ", " salsa ", " ballet ", " stepping ... | openstax_introduction_to_python_programming_-_web | [
0.010988282971084118,
-0.02753922902047634,
-0.0163546372205019,
0.0034324706066399813,
-0.002708373824134469,
-0.010681912302970886,
-0.02323891595005989,
0.015550070442259312,
-0.020372390747070312,
0.08399902284145355,
-0.007178083062171936,
0.024444494396448135,
0.027601508423686028,
-... |
9. 3 common list operations learning objectives by the end of this section you should be able to • use built - in functions max ( ), min ( ), and sum ( ). • demonstrate how to copy a list. using built - in operations the max ( ) function called on a list returns the largest element in the list. the min ( ) function cal... | openstax_introduction_to_python_programming_-_web | [
0.005907224491238594,
0.0020440632943063974,
0.01182118896394968,
0.0122202904894948,
-0.026374494656920433,
-0.0230861846357584,
-0.01778395101428032,
-0.004988385364413261,
-0.018953368067741394,
0.07477647811174393,
0.008124878630042076,
0.0525682307779789,
0.010939879342913628,
-0.0416... |
9. 3 • common list operations 229 999 sacramento - 5 austin 1135 concepts in practice list operations 1. what is the correct way to get the minimum of a list named nums _ list? a. min ( nums _ list ) b. nums _ list. min ( ) c. minimum ( nums _ list ) 2. what is the minimum of the following list? [ " lollapalooza ", " c... | openstax_introduction_to_python_programming_-_web | [
0.031845495104789734,
-0.009431742131710052,
0.007945057936012745,
0.005806739907711744,
-0.02806655503809452,
-0.027554994449019432,
0.015027202665805817,
0.009852002374827862,
0.00017466802091803402,
0.059902824461460114,
0.03516300395131111,
0.013958682306110859,
-0.024470917880535126,
... |
12. 4 copying a list the copy ( ) method is used to create a copy of a list. checkpoint copying a list access multimedia content ( https : / / openstax. org / books / introduction - python - programming / pages / 9 - 3 - common - list - operations ) concepts in practice copying a list 4. what is the output of the follo... | openstax_introduction_to_python_programming_-_web | [
0.025840414687991142,
-0.028252802789211273,
0.04461245611310005,
-0.019411295652389526,
-0.01770883984863758,
-0.035838015377521515,
-0.0485089085996151,
0.00485569704324007,
0.05149559676647186,
0.06022091954946518,
-0.03160662204027176,
0.03240228816866875,
0.022748548537492752,
0.00066... |
lists. | openstax_introduction_to_python_programming_-_web | [
0.004034762270748615,
-0.020276740193367004,
0.0036672367714345455,
0.029765535145998,
-0.05886392667889595,
-0.007828615605831146,
0.00879011582583189,
0.03535746410489082,
0.04066099599003792,
0.0459718182682991,
0.0007400860195048153,
0.02929561585187912,
0.016170980408787727,
-0.006566... |
9. 4 • nested lists 231 list - of - lists lists can be made of any type of element. a list element can also be a list. ex : [ 2, [ 3, 5 ], 17 ] is a valid list with the list [ 3, 5 ] being the element at index 1. when a list is an element inside a larger list, it is called a nested list. nested lists are useful for exp... | openstax_introduction_to_python_programming_-_web | [
0.010309169068932533,
-0.003290851367637515,
0.02027384378015995,
-0.016177870333194733,
-0.00022469292161986232,
-0.018397627398371696,
-0.023889770731329918,
-0.025710642337799072,
0.014059417881071568,
0.09223423898220062,
-0.008347123861312866,
0.06539569050073624,
0.019539980217814445,
... |
a list - of - lists. for a two - dimensional list - of - lists, an outer for loop can be used for rows, and an inner for loop can be used for columns. 232 9 • lists access for free at openstax. org example 9. 4 iterating a list - of - lists the code below demonstrates how to iterate a list - of - lists. the outer loop ... | openstax_introduction_to_python_programming_-_web | [
0.026570050045847893,
0.001144304173067212,
0.009937314316630363,
-0.002121565630659461,
-0.04069369286298752,
-0.021596938371658325,
-0.0439206101000309,
-0.0343487374484539,
0.022988762706518173,
0.10249210149049759,
0.002373959170654416,
0.032741233706474304,
-0.012675890699028969,
-0.0... |
then 4, and so on, ending with - 5, using counting for loops? | openstax_introduction_to_python_programming_-_web | [
0.020180612802505493,
0.0015922802267596126,
0.021421387791633606,
-0.015183858573436737,
-0.008772349916398525,
-0.06386356800794601,
0.009006488136947155,
0.02324674464762211,
-0.05144631862640381,
0.07676898688077927,
0.030249714851379395,
0.0029733581468462944,
-0.025294581428170204,
-... |
9. 4 • nested lists 233 a. for column _ index in range ( 0, len ( my _ list [ 0 ] ) ) : for row _ index in range ( 0, len ( my _ list ) ) : print ( my _ list [ row _ index ] [ column _ index ] ) b. for row _ index in range ( 0, len ( my _ list ) ) : for column _ index in range ( 0, len ( my _ list ) ) : print ( my _ li... | openstax_introduction_to_python_programming_-_web | [
0.019375696778297424,
-0.013852186501026154,
0.014953023754060268,
-0.035154324024915695,
0.011387917213141918,
-0.03964747115969658,
-0.02180957980453968,
-0.01495234202593565,
-0.006759388372302055,
0.07711169123649597,
0.004449879750609398,
0.05886097997426987,
-0.00617760606110096,
-0.... |
9. 5 list comprehensions learning objectives by the end of this section you should be able to • identify the different components of a list comprehension statement. • implement filtering using list comprehension. 234 9 • lists access for free at openstax. org list comprehensions a list comprehension is a python stateme... | openstax_introduction_to_python_programming_-_web | [
-0.009020141325891018,
-0.03247605636715889,
0.04723264276981354,
-0.01238294318318367,
-0.022308319807052612,
-0.028344281017780304,
0.021838003769516945,
-0.006561379414051771,
0.01037092786282301,
0.0903233215212822,
-0.0221260879188776,
0.022396160289645195,
0.0164883304387331,
-0.0255... |
", " two ", " red ", " blue " ] 3 4 # use a list comprehension to create a new list called poem _ lines 5 # inserting the word " fish " attached to each word in words _ list 6 poem _ lines = [ w + " fish " for w in words _ list ] | openstax_introduction_to_python_programming_-_web | [
-0.0011042054975405335,
-0.0018276846967637539,
0.020622827112674713,
-0.03223245590925217,
-0.039359573274850845,
-0.0451202429831028,
0.02376328594982624,
0.02427987940609455,
0.04330350086092949,
0.06616527587175369,
-0.0009396269451826811,
0.008825944736599922,
0.037500277161598206,
-0... |
9. 5 • list comprehensions 235 7 for line in poem _ lines : 8 print ( line ) the above code's output is : one fish two fish red fish blue fish concepts in practice list comprehensions 1. the component of a list comprehension defining an element of the new list is the _ _ _ _ _. a. expression b. loop _ variable c. conta... | openstax_introduction_to_python_programming_-_web | [
-0.0027576028369367123,
-0.02412569709122181,
0.042738109827041626,
-0.005146135110408068,
-0.016966091468930244,
-0.0439143106341362,
0.012580798007547855,
-0.0038158451206982136,
0.013954325579106808,
0.08711361140012741,
-0.02084977738559246,
0.02842075191438198,
0.009863520972430706,
-... |
##x. org / books / introduction - python - programming / pages / 9 - 5 - list - comprehensions ) concepts in practice filtering using list comprehensions for each code using list comprehension, select the correct resultant list in new _ list. 4. my _ list = [ 21, - 1, 50, - 9, 300, - 50, 2 ] new _ list = [ m for m in m... | openstax_introduction_to_python_programming_-_web | [
0.022770389914512634,
-0.014101330190896988,
0.040696002542972565,
-0.0072179329581558704,
-0.042521290481090546,
-0.021770333871245384,
-0.00603000121191144,
0.01792323775589466,
-0.022786352783441544,
0.08877326548099518,
-0.01623564399778843,
0.010932108387351036,
0.011264313012361526,
... |
openstax. org / books / introduction - python - programming / pages / 9 - 5 - list - comprehensions ) | openstax_introduction_to_python_programming_-_web | [
0.0027767792344093323,
0.009375590831041336,
0.003156947437673807,
0.006722376216202974,
-0.030269550159573555,
-0.018260126933455467,
-0.00648187380284071,
0.0005432250327430665,
0.004696139600127935,
0.08321224898099899,
0.009115152060985565,
0.042077258229255676,
0.03224155679345131,
0.... |
9. 6 chapter summary highlights from this chapter include : • lists are mutable and can be easily modified by using append ( ), remove ( ), and pop ( ) operations. • lists are iterable and can be iterated using an iterator or element indexes. • the sort ( ) operation arranges the elements of a list in ascending order i... | openstax_introduction_to_python_programming_-_web | [
-0.02186136320233345,
-0.028486937284469604,
-0.003993581514805555,
-0.03694681078195572,
0.004489326383918524,
-0.01824692264199257,
-0.039400435984134674,
-0.0004410991969052702,
0.012185669504106045,
0.10814499109983444,
-0.0206733588129282,
0.010595926083624363,
0.010292614810168743,
-... |
##k / flickr, cc by 2. 0 chapter outline 10. 1 dictionary basics 10. 2 dictionary creation 10. 3 dictionary operations 10. 4 conditionals and looping in dictionaries 10. 5 nested dictionaries and dictionary comprehension 10. 6 chapter summary introduction a python dictionary is a data type for storing the data in a key... | openstax_introduction_to_python_programming_-_web | [
0.0013247786555439234,
-0.01707351952791214,
-0.0015641083009541035,
-0.04628438875079155,
-0.01785072684288025,
-0.017053747549653053,
0.018111029639840126,
0.0001588031300343573,
0.00950157642364502,
0.07392147928476334,
-0.006759535055607557,
-0.01605381816625595,
-0.006700619123876095,
... |
10. 1 dictionary basics learning objectives by the end of this section you should be able to • describe the structure of a dictionary object. • use type ( ) to identify the type of a dictionary object. • explain why a dictionary object does not have duplicate key values. dictionaries a dictionary in python is a contain... | openstax_introduction_to_python_programming_-_web | [
0.021741988137364388,
-0.0007375171408057213,
0.002295439364388585,
-0.02271704003214836,
-0.010628842748701572,
-0.002941564889624715,
0.0183725468814373,
0.00372516131028533,
0.013582845218479633,
0.06683909893035889,
0.005940488073974848,
-0.015649694949388504,
0.02994108572602272,
0.03... |
encoding ) return? 242 10 • dictionaries access for free at openstax. org a. dictionary b. dict c. str 5. the encoding dictionary contains duplicate keys since it has both " a " and " a " as keys. a. true b. false 6. a dictionary can have duplicate values. a. true b. false try it investigate variable types given the va... | openstax_introduction_to_python_programming_-_web | [
0.023890117183327675,
0.006097751669585705,
0.01936907321214676,
0.013783060945570469,
-0.00891180895268917,
-0.01743513159453869,
0.01874541863799095,
-0.007289898581802845,
0.004960161633789539,
0.08856427669525146,
-0.012026242911815643,
-0.012915469706058502,
0.007964333519339561,
0.00... |
10. 2 dictionary creation learning objectives by the end of this section you should be able to • create a dictionary object with given key / value pairs. dictionary creation two methods exist for creating an empty dictionary : • using curly braces { }. ex : dict _ 1 = { }. • using the dict ( ) function. ex : dict _ 2 =... | openstax_introduction_to_python_programming_-_web | [
-0.003485777648165822,
0.002951335860416293,
0.006203996017575264,
-0.039226967841386795,
-0.028549814596772194,
-0.00709913857281208,
0.018813788890838623,
0.017820263281464577,
0.013592904433608055,
0.07534614950418472,
0.01430103275924921,
-0.01692265272140503,
-0.004847401287406683,
-0... |
10. 2 • dictionary creation 243 concepts in practice creating dictionary exercises 1. what is the correct syntax to create an empty dictionary in python? a. my _ dict = ( ) b. my _ dict = { } c. my _ dict = [ ] 2. what is the correct syntax to create a dictionary with one item " one " : 1? a. my _ dict = ( " one " : 1 ... | openstax_introduction_to_python_programming_-_web | [
0.012106088921427727,
-0.0029472222086042166,
0.01177810225635767,
-0.04368984326720238,
-0.041805315762758255,
-0.025359801948070526,
0.033865634351968765,
-0.010989310219883919,
-0.0001922069932334125,
0.07465231418609619,
0.010927869938313961,
0.0026834753807634115,
-0.01414718572050333,
... |
initial values in python? a. my _ dict = [ key1 : value1, key2 : value2 ] b. my _ dict = dict ( key1 = value1, key2 = value2 ) c. my _ dict = { key1 = value1, key2 = value2 } 5. what is the output of the following code? my _ dict = dict ( { " a " : 1 } ) print ( my _ dict ) a. { " a " : 1 } b. < class,'dict'> c. " a " ... | openstax_introduction_to_python_programming_-_web | [
-0.00023278464504983276,
-0.020650681108236313,
-0.005059954710304737,
-0.0677209123969078,
-0.03064875677227974,
-0.015741219744086266,
-0.005072509404271841,
-0.023839861154556274,
0.016564572229981422,
0.07206672430038452,
-0.006098401732742786,
-0.012839945033192635,
0.030587421730160713... |
using the keys as indexes. here are two ways to access dictionary items in python : | openstax_introduction_to_python_programming_-_web | [
-0.029569093137979507,
-0.022330980747938156,
-0.0068353391252458096,
-0.0059470185078680515,
-0.012196035124361515,
-0.007945986464619637,
0.005630207248032093,
-0.009115916676819324,
0.02985399402678013,
0.09098828583955765,
0.014810820110142231,
0.009315683506429195,
-0.023962408304214478... |
10. 3 • dictionary operations 245 • square bracket notation : square brackets [ ] with the key inside access the value associated with that key. if the key is not found, an exception will be thrown. • get ( ) method : the get ( ) method is called with the key as an argument to access the value associated with that key.... | openstax_introduction_to_python_programming_-_web | [
-0.03496634587645531,
-0.0017992991488426924,
-0.04040045663714409,
0.0017426267731934786,
-0.03842509910464287,
-0.0005912748747505248,
-0.013449576683342457,
-0.01135035790503025,
0.006494272965937853,
0.07612025737762451,
0.01332045253366232,
-0.007812959142029285,
-0.013099615462124348,
... |
. 0 b. none c. " student " 3. what is the output of members. get ( " jaya ", " does not exist " )? a. " student " b. " does not exist " c. none obtaining dictionary keys and values dictionary keys, values, and both keys and values can be obtained using keys ( ), values ( ), and items ( ) 246 10 • dictionaries access fo... | openstax_introduction_to_python_programming_-_web | [
-0.004616635385900736,
-0.007009523920714855,
-0.004322887863963842,
-0.015055809170007706,
-0.047002241015434265,
-0.027151761576533318,
-0.02872985415160656,
-0.007719501852989197,
0.017490733414888382,
0.07107119262218475,
-0.006011554505676031,
-0.001342853414826095,
-0.00197709794156253... |
dictionary numbers = { " one " : 1, " two " : 2, " three " : 3 }, answer the following questions. 4. what is the output type of numbers. keys ( )? a. dict _ keys b. dict _ values c. list 5. what is the output of print ( numbers. values ( ) )? a. [ 1, 2, 3 ] b. dict _ keys ( [ 1, 2, 3 ] ) c. dict _ values ( [ 1, 2, 3 ] ... | openstax_introduction_to_python_programming_-_web | [
0.02184179425239563,
-0.018033139407634735,
0.014203519560396671,
-0.03694457188248634,
-0.028439493849873543,
-0.018912311643362045,
0.008211549371480942,
0.019442351534962654,
0.0033978400751948357,
0.0654178112745285,
-0.0066740973852574825,
0.004626161884516478,
0.017615074291825294,
-... |
10. 3 • dictionary operations 247 dictionary mutability in python, a dictionary is a mutable data type, which means that a dictionary's content can be modified after creation. dictionary items can be added, updated, or deleted from a dictionary after a dictionary object is created. to add an item to a dictionary, eithe... | openstax_introduction_to_python_programming_-_web | [
-0.033299099653959274,
-0.00963298324495554,
-0.027580590918660164,
-0.009052266366779804,
-0.016074184328317642,
-0.019031548872590065,
0.0014778194017708302,
-0.03775040805339813,
0.037921588867902756,
0.08398240804672241,
0.017314620316028595,
-0.0316462516784668,
0.0006280789966695011,
... |
" orange " : 4 } • update ( ) method : my _ dict = { " apple " : 2, " banana " : 3, " orange " : 4 } my _ dict. update ( { " apple " : 1 } ) print ( my _ dict ) # prints : { " apple " : 1, " banana " : 3, " orange " : 4 } items can be deleted from a dictionary using the del keyword or the pop ( ) method. • del keyword ... | openstax_introduction_to_python_programming_-_web | [
-0.008892136625945568,
-0.013432568870484829,
-0.007315929513424635,
0.025890754535794258,
-0.033546626567840576,
-0.05302503705024719,
0.013873971998691559,
-0.018282730132341385,
0.0026246830821037292,
0.07789861410856247,
0.00507115013897419,
-0.011361835524439812,
-0.000455644418252632,
... |
soup " ] = 11 c. food [ " coconut soup " ] = " $ 11 " 8. which option removes the item " butter chicken " : " $ 18 " from the food dictionary? a. food. remove ( " butter chicken " ) b. del food [ " butter chicken " ] c. del food. del ( " butter chicken " ) 9. what is the content of the food dictionary after calling foo... | openstax_introduction_to_python_programming_-_web | [
-0.012976914644241333,
0.020947681739926338,
-0.0016346531920135021,
0.008347531780600548,
-0.017271585762500763,
-0.012546882964670658,
0.035224828869104385,
0.006973517592996359,
0.002620777115225792,
0.05574462562799454,
0.027187595143914223,
0.004949368070811033,
0.003602426266297698,
... |
- python - programming / pages / 10 - 3 - dictionary - operations ) try it the number of unique characters given a string value, calculate and print the number of unique characters using a dictionary. input : string _ value = " this is a string " prints 10 access multimedia content ( https : / / openstax. org / books /... | openstax_introduction_to_python_programming_-_web | [
0.010580417700111866,
0.012813127599656582,
-0.01646309904754162,
0.0164080411195755,
-0.004477553069591522,
-0.012269878759980202,
-0.0031274030916392803,
-0.018826408311724663,
0.0333767794072628,
0.043919265270233154,
0.012830473482608795,
0.00017392892914358526,
0.0038288950454443693,
... |
10. 4 conditionals and looping in dictionaries learning objectives by the end of this section you should be able to • write a conditional statement to check for a key / value. • write a for loop to iterate over elements of a dictionary. conditionals for dictionary conditional statements can be used with dictionaries to... | openstax_introduction_to_python_programming_-_web | [
-0.0019178712973371148,
0.004485627636313438,
0.003914509899914265,
-0.009987370111048222,
-0.017809366807341576,
-0.009723818860948086,
0.014759297482669353,
-0.01688997820019722,
0.002470136620104313,
0.0609554648399353,
0.005021145101636648,
-0.0049971845000982285,
0.012135261669754982,
... |
10. 4 • conditionals and looping in dictionaries 251 dict. keys ( ) # key in dictionary. keys ( ) movies = { " the godfather " : 1974, " interstellar " : 2014 } print ( " interstellar " in movies. keys ( ) ) true table 10. 3 dict. values ( ) # value in dictionary. values ( ) movies = { " the godfather " : 1974, " inter... | openstax_introduction_to_python_programming_-_web | [
0.01514467503875494,
0.010301973670721054,
-0.007200024090707302,
-0.011544520035386086,
-0.009762982837855816,
-0.03662152588367462,
-0.001345158088952303,
-0.022688450291752815,
0.0047942958772182465,
0.05877096951007843,
-0.01938239485025406,
0.0004936576588079333,
0.006095536984503269,
... |
to the loop variable. a for loop over a dictionary retrieves each key in the dictionary for key in dictionary : # loop expression # statements to execute in the loop # statements to execute after the loop example 10. 3 iterating over a dictionary dict. items ( ) zip _ codes = { " berkeley " : 94709, " santa cruz " : 95... | openstax_introduction_to_python_programming_-_web | [
-0.01903824508190155,
-0.01855592615902424,
-0.0038606328889727592,
0.01631070300936699,
-0.02150747925043106,
-0.04007135331630707,
0.011990771628916264,
-0.013097919523715973,
0.004593807738274336,
0.08689746260643005,
-0.006160599645227194,
-0.005627449601888657,
-0.01963394321501255,
-... |
10. 4 • conditionals and looping in dictionaries 253 dict. keys ( ) zip _ codes = { " berkeley " : 94709, " santa cruz " : 95064, " mountain view " : 94030 } for key in zip _ codes. keys ( ) : print ( key ) berkeley santa cruz mountain view table 10. 6 dict. values ( ) zip _ codes = { " berkeley " : 94709, " santa cruz... | openstax_introduction_to_python_programming_-_web | [
0.0204478707164526,
0.007462887559086084,
0.021968353539705276,
-0.000814828381408006,
-0.00401622150093317,
-0.03558900207281113,
0.019405078142881393,
-0.020593903958797455,
0.0007662542047910392,
0.0880594477057457,
-0.008020590990781784,
-0.022338299080729485,
0.013659129850566387,
-0.... |
t " : 1, " h " : 1, " i " : 3, " s " : 3, " " : 3, " a " : 1, " t " : 1, " r " : 1, " n " : 1, " g " : 1 } access multimedia content ( https : / / openstax. org / books / introduction - python - programming / pages / 10 - 4 - conditionals - and - looping - in - dictionaries ) try it calculate the total number of fruits... | openstax_introduction_to_python_programming_-_web | [
0.022323470562696457,
0.01531731802970171,
0.0038690415676683187,
-0.03027213364839554,
-0.005626953672617674,
-0.035200390964746475,
0.011143524199724197,
-0.005361995659768581,
0.03192906081676483,
0.06243402883410454,
0.0040452443063259125,
-0.016297973692417145,
-0.007294642738997936,
... |
10. 5 nested dictionaries and dictionary comprehension learning objectives by the end of this section you should be able to • explain the structure of nested dictionaries. • use dictionary comprehension to create a dictionary object. nested dictionaries as described before, python dictionaries are a type of data struct... | openstax_introduction_to_python_programming_-_web | [
0.011899802833795547,
-0.01485460065305233,
-0.011671404354274273,
-0.05945311859250069,
0.00660862447693944,
0.014445601031184196,
0.010099639184772968,
0.0018185368971899152,
0.007017791736871004,
0.06099458038806915,
-0.023339277133345604,
0.03970467299222946,
0.004346711095422506,
-0.0... |
a dictionary that contains only strings as keys and values. | openstax_introduction_to_python_programming_-_web | [
-0.01312058512121439,
-0.00023836061882320791,
0.044777534902095795,
-0.03325505554676056,
-0.0310366153717041,
-0.02313315123319626,
0.030744114890694618,
-0.010318445973098278,
0.013298808597028255,
0.05198855325579643,
0.009557409211993217,
-0.042271438986063004,
-0.011847746558487415,
... |
10. 5 • nested dictionaries and dictionary comprehension 257 d. a dictionary that contains only lists as keys and values. 2. how can a value be accessed in a nested dictionary in python? a. by using the key of the outer dictionary b. by using the key of the inner dictionary c. by using both the keys of the outer and in... | openstax_introduction_to_python_programming_-_web | [
0.00673183286562562,
0.004801469389349222,
-0.004660482984036207,
-0.03594757243990898,
-0.024289336055517197,
-0.0023627777118235826,
0.009755188599228859,
-0.012671652249991894,
0.01206374540925026,
0.081900954246521,
-0.03990243375301361,
0.05238955840468407,
-0.0070217084139585495,
-0.... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.