[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-417796-105":3,"detail-sidebar-cat-0-en-105":85,"doc-detail-417796-en":134},{"code":4,"msg":5,"data":6},0,"ok",{"site_id":7,"language":8,"slug":9,"title":10,"keywords":11,"description":12,"schema_data":13,"social_meta":78,"head_meta":80,"extra_data":82,"updated_unix":84},105,"en","pftweek-python-basics-variables-types-and-operators","PFTWeek - Python Basics - Variables, Types, and Operators","","PFTWeek lecture materials for Compsci 101.2 (Fall 2015) covering core Python concepts and problem-solving workflow. Topics include control flow (if/elif/else, for), data (strings, lists), operators and expressions (arithmetic, boolean, string concatenation, slicing and indexing), and the fundamentals of variables, types, and values. The notes also emphasize functions and returns, abstraction and parameterization, type inspection with type(..), expression precedence, and common pitfalls in operator use, followed by practice and testing prompts based on example problems.",{"@graph":14,"@context":77},[15,34,56],{"@type":16,"itemListElement":17},"BreadcrumbList",[18,23,27,31],{"item":19,"name":20,"@type":21,"position":22},"https://docshare.wps.com","Home","ListItem",1,{"item":24,"name":25,"@type":21,"position":26},"https://docshare.wps.com/document/","Document",2,{"item":28,"name":29,"@type":21,"position":30},"https://docshare.wps.com/document/exam/","Exam",3,{"item":32,"name":10,"@type":21,"position":33},"https://docshare.wps.com/document/pftweek-python-basics-variables-types-and-operators/417796/",4,{"url":32,"name":10,"@type":35,"image":36,"author":41,"headline":10,"publisher":44,"fileFormat":47,"inLanguage":8,"description":12,"dateModified":48,"datePublished":49,"encodingFormat":47,"isAccessibleForFree":50,"interactionStatistic":51},"DigitalDocument",{"url":37,"@type":38,"width":39,"height":40},"https://docshare.wps.com/thumbnails/pftweek-python-basics-variables-types-and-operators/417796.png","ImageObject",300,407,{"name":42,"@type":43},"Riley","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-11-09","2026-09-28",true,{"@type":52,"interactionType":53,"userInteractionCount":55},"InteractionCounter",{"@type":54},"ViewAction",7,{"@type":57,"mainEntity":58},"FAQPage",[59,65,69,73],{"name":60,"@type":61,"acceptedAnswer":62},"What Python control structures are introduced in these notes?","Question",{"text":63,"@type":64},"The notes introduce control flow using if/elif/else and for loops to guide decision-making and repetition.","Answer",{"name":66,"@type":61,"acceptedAnswer":67},"How do variables relate to names, types, and values in Python?",{"text":68,"@type":64},"A variable is a name associated with storage; it holds a value, and the code can be analyzed in terms of the name, the variable’s type, and its current value.",{"name":70,"@type":61,"acceptedAnswer":71},"What does slicing and indexing cover for strings and lists?",{"text":72,"@type":64},"The notes explain that str and list support indexing (including negative indices) and slicing with ranges and step sizes, such as s[5:11] and s[::-1].",{"name":74,"@type":61,"acceptedAnswer":75},"What key idea is emphasized about functions and return values?",{"text":76,"@type":64},"The material highlights defining functions, calling them, and using return types (including print, None) to organize solutions and support re-use through parameterization.","https://schema.org",{"og:url":32,"og:type":79,"og:title":10,"og:site_name":45,"og:description":12},"article",{"robots":81,"canonical":32},"index,follow",{"doc_id":83,"site_id":7},417796,1790891794,{"code":4,"msg":86,"data":87},"success",[88,92,96,99,104,109,113,118,123,126,130],{"id":22,"doc_module":4,"doc_module_name":25,"category_name":89,"show_sort_weight":90,"slug":91},"Story & Novel",90,"story-novel",{"id":26,"doc_module":4,"doc_module_name":25,"category_name":93,"show_sort_weight":94,"slug":95},"Literature",80,"literature",{"id":33,"doc_module":4,"doc_module_name":25,"category_name":29,"show_sort_weight":97,"slug":98},70,"exam",{"id":100,"doc_module":4,"doc_module_name":25,"category_name":101,"show_sort_weight":102,"slug":103},5,"Comic",60,"comic",{"id":105,"doc_module":4,"doc_module_name":25,"category_name":106,"show_sort_weight":107,"slug":108},6,"Technology",50,"technology",{"id":55,"doc_module":4,"doc_module_name":25,"category_name":110,"show_sort_weight":111,"slug":112},"Healthcare",40,"healthcare",{"id":114,"doc_module":4,"doc_module_name":25,"category_name":115,"show_sort_weight":116,"slug":117},8,"Research & Report",30,"research-report",{"id":119,"doc_module":4,"doc_module_name":25,"category_name":120,"show_sort_weight":121,"slug":122},9,"Religion & Spirituality",20,"religion-spirituality",{"id":121,"doc_module":4,"doc_module_name":25,"category_name":124,"show_sort_weight":121,"slug":125},"World Cup","world-cup",{"id":127,"doc_module":4,"doc_module_name":25,"category_name":128,"show_sort_weight":127,"slug":129},10,"Lifestyle","lifestyle",{"id":131,"doc_module":4,"doc_module_name":25,"category_name":132,"show_sort_weight":100,"slug":133},19,"General","general",{"code":4,"msg":86,"data":135},{"doc_id":83,"user_id":136,"nickname":42,"user_avatar":137,"doc_module":4,"category_id":33,"category_name":29,"doc_title":10,"doc_description":12,"doc_content":138,"file_id":139,"file_url":140,"file_type":141,"file_size":142,"view_count":55,"is_deleted":4,"is_public":22,"is_downloadable":22,"audit_status":22,"page_count":55,"language":143,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":144,"faqs":145,"seo_title":146,"seo_description":12,"update_tm":147,"read_time":148,"preview_page_count":4},1374391975076,"https://ap-avatar.wpscdn.com/avatar/14000253ca4ec9f6853?x-image-process=image/resize,m_fixed,w_180,h_180&k=1783305029341752051","PFTWeek  \n● Introduce new Python concepts  \n􀀡 Control: if, elif, else, for  \n􀀡 Data: Strings, Lists  \n• Operators on data: slicing, methods, functions  \n􀀡 Variables and constants:  \n• Names, types, and values  \n● Review Organization and Problem-Solving  \n􀀡 Defining functions, calling functions  \n􀀡 Return types, print, None  \nCompsci 101.2, Fall 2015 5.1  \nVocabulary, grammar, rules: Python  \n● Naming  \n􀀡 The power of abstraction and parameterization  \n􀀡 What are parameters? What has them (Python, World)?  \n● Types  \n􀀡 What's used in computing? What's used in Python?  \n􀀡 Determine names of types in Python, use type(..)  \n● Expressions and operators in Python  \n􀀡 Arithmetic: +, - , *, /, %, **, …  \n􀀡 Boolean: \u003C, ==, >, and, ...  \n􀀡 String: +, *, [], [:], [::]  \nCompsci 101.2, Fall 2015 5.3  \n\n| Variables, Types, Values\u003Cbr>● Variable is a name associated with \"storage\"\u003Cbr>􀀡 Assign a value: x = 5\u003Cbr>􀀡 Print value of variable: print x\u003Cbr>􀀡 Use variable in expression: y = x * 55 |  |\n| --- | --- |\n| ● String is a type and has a value\u003Cbr>􀀡 Assign: x = \"hello\"\u003Cbr>􀀡 Print value of variable: print x\u003Cbr>􀀡 Use in expression\u003Cbr>• print len(x) | |\n| • print x + \" world\"\u003Cbr>● There are more types, this is a start!\u003Cbr>Compsci 101.2, Fall 2015 5.2 |  |\n\nTypes and values in Python  \n● Numbers are important, but not everything is a …  \n􀀡 What is a number? In mathematics, in Python, in Java,􀀡 Integers, floating-point numbers, complex numbers,…  \n• We will worry about types, not speed or storage (though these are a concern sometimes)  \n• 1,2,3 compared to 3.1415, 1.75, math.pi  \n• 5/2 compared to 5.0/2 compared to 5//2  \n● Strings are sequences of characters, \"[python.org](python.org)\"  \n􀀡 Somewhere these are converted to numbers: 0's and 1's  \n􀀡 No real need to know this now.  \n􀀡 Strings are immutable: make new ones, can't change them  \nCompsci 101.2, Fall 2015 5.4  \n\n| Expressions, Operators, Types\u003Cbr>● Why is 3+5*4 different than (3+5)*4?\u003Cbr>􀀡 Where can you find information about precedence?\u003Cbr>● Why is 5/3 different than 5 .0/3?\u003Cbr>􀀡 What will happen in Python 3? Accommodate in 2.7?\u003Cbr>● What happens when operators go bad?\u003Cbr>􀀡 What is \"apple\" + 3? What is \"apple\" + \"pi\"?\u003Cbr>􀀡 What is \"apple\" * 3? What is \"apple\" * \"pi\" ?\u003Cbr>● What is a variable in Python?\u003Cbr>􀀡 Name, Type, Value\u003Cbr>Compsci 101.2, Fall 2015 | 5.5 |\n| --- | --- |\n\n\n| Names, Types, Values Revisited |  |\n| --- | --- |\n| name = \"/data/poe .txt\"\u003Cbr>ff = open(name)\u003Cbr>[st = ff.read](st = ff.read) () words = st.split()\u003Cbr>print \"\\# words in\",name, \"=\",len(words)\u003Cbr>● What are the names in the code above?\u003Cbr>􀀡 Why are names important?\u003Cbr>● What are the types in the code above?\u003Cbr>􀀡 How do we get Python to help us answer this question\u003Cbr>● How do we re-use this code more generally\u003Cbr>􀀡 The power of names! The power of functions!\u003Cbr>Compsci 101.2, Fall 2015 | 5.7 |\n\nObservations about String literals  \n● Sometimes the details are tricky  \n􀀡 \"I \" + \"love \" + 'Python'  \n􀀡 \"I \" + \"love \" + '\"Python\"'  \n􀀡 \"I \" + \"love \" + \"'Python'\"  \n● When in doubt, use parentheses  \n􀀡 What is \"a\" + \"b\" * 3  \n􀀡 What is \"a\" \"b\" * 3  \nCompsci 101.2, Fall 2015 5.6  \n\n| Slicing and Indexing\u003Cbr>● The Python types str (String) and list both support indexing and slicing\u003Cbr>s = \"blue devils at duke\" 0123456789012345678\u003Cbr>● s[1], s[2], s[0], s[50]\u003Cbr>● s[-1], s[-4]\u003Cbr>● s[5:11], s[15:], s[:4], s[:]\u003Cbr>● s[5:10:2], s[:], s[::-1]\u003Cbr>Compsci 101.2, Fall 2015 | 5.8 |\n| --- | --- |\n\nValue Expert  \n● Answer these questions  \n[http://bit.ly/101fall15-0903-2](http://bit.ly/101fall15-0903-2)  \nCompsci 101.2, Fall 2015 5.9  \nAPT Pancake: [http://bit.ly/pancakes101](http://bit.ly/pancakes101)  \n● How do you solve this problem?  \n􀀡 First steps: are there simple cases that can be solved immediately?  \n• What are these for the pancake problem?  \n􀀡 Sometimes it helps to know if you are on track, should you use Python to check your paper and pencil work?  \n● Get specific, solve for 5, not N  \n􀀡 Fix one parameter, vary the other  ","cbCaigfQhk51yomj","https://ap.wps.com/l/cbCaigfQhk51yomj","pdf",3843979,"English","# Python concepts overview\n## Control flow and data\n## Variables, types, values\n## Expressions and operators\n## Functions and return values\n## Naming, abstraction, and parameterization\n# Practice and problem-solving","[{\"question\":\"What Python control structures are introduced in these notes?\",\"answer\":\"The notes introduce control flow using if/elif/else and for loops to guide decision-making and repetition.\"},{\"question\":\"How do variables relate to names, types, and values in Python?\",\"answer\":\"A variable is a name associated with storage; it holds a value, and the code can be analyzed in terms of the name, the variable’s type, and its current value.\"},{\"question\":\"What does slicing and indexing cover for strings and lists?\",\"answer\":\"The notes explain that str and list support indexing (including negative indices) and slicing with ranges and step sizes, such as s[5:11] and s[::-1].\"},{\"question\":\"What key idea is emphasized about functions and return values?\",\"answer\":\"The material highlights defining functions, calling them, and using return types (including print, None) to organize solutions and support re-use through parameterization.\"}]","PFTWeek - Python Basics - Variables, Types, and Operators | PDF",1790610654,18]