Innovation Course | Basics of Python (Part 3)

Innovation Course | Basics of Python (Part 3)

Basics

Python

(Part 3)

Innovation Course | Basics of Python (Part 3)

Dear students, have you ever wondered how computers understand human commands and perform various complex tasks? Today, let us unveil the mystery of programming and step into the fascinating world of the Python programming language!

Python is like a “foreign language” for conversing with computers, but it is more concise and precise than human languages. In this course, we will start from the most basic concepts and gradually master the core skills of Python. You will find that programming is not an unattainable skill, but a powerful tool for realizing creativity and solving problems.

In this course, you will not only learn programming knowledge but also develop problem-solving abilities. Each debugging error and every successful program run is an exercise in patience and logical thinking. The world of programming is full of challenges, but it is also filled with fun and a sense of accomplishment.

Are you ready? Let’s type our first line of code together and embark on this creative journey! The future technological world is waiting for you to write your own chapter with Python!

Exploring Data Containers

Innovation Course | Basics of Python (Part 3)Innovation Course | Basics of Python (Part 3)Innovation Course | Basics of Python (Part 3)Innovation Course | Basics of Python (Part 3)Innovation Course | Basics of Python (Part 3)Innovation Course | Basics of Python (Part 3)

Python treats everything as an object. Numbers fall into three categories: integers (e.g., 132224) support large number calculations (1323232=17509376329L); floating-point numbers (e.g., 1.23232) require attention to precision issues (print can optimize display); complex numbers (e.g., 3+2j) directly support vector calculations.

Innovation Course | Basics of Python (Part 3)Innovation Course | Basics of Python (Part 3)Innovation Course | Basics of Python (Part 3)

Strings are like chains of characters. Single or double quotes define the content, and ” + ” concatenates the chain (e.g., ‘hello’ + ‘ there’ = ‘hello there’), while slicing extracts segments (e.g., if s=’012345′, then s[1:4]=’123′).

Innovation Course | Basics of Python (Part 3)

Formatting allows flexible data assembly: “%d, two, %s” % (1,3) outputs “1, two, 3”.

Innovation Course | Basics of Python (Part 3)Innovation Course | Basics of Python (Part 3)

The four major containers each have their roles:

Lists are like ordered shelves, capable of storing mixed types (e.g., [1,’hello’,(3+2j)]).

Innovation Course | Basics of Python (Part 3)Innovation Course | Basics of Python (Part 3)Innovation Course | Basics of Python (Part 3)

Use append to add items and pop to remove the last item. Be cautious of reference traps: when y=x, modifying x[1]=15 will change y as well; however, x=x+[9,10] creates a new list.

Innovation Course | Basics of Python (Part 3)Innovation Course | Basics of Python (Part 3)

Tuples are like sealed boxes, and cannot be modified once created (e.g., (1,2,3)).

Innovation Course | Basics of Python (Part 3)Innovation Course | Basics of Python (Part 3)

Sets are like mathematical sets, supporting operations like intersection (&) and union (|).

Innovation Course | Basics of Python (Part 3)Innovation Course | Basics of Python (Part 3)Innovation Course | Basics of Python (Part 3)Innovation Course | Basics of Python (Part 3)

Dictionaries are like password books: they store key-value pairs (e.g., {‘one’:1, ‘two’:2}), and del removes entries. During iteration, “for k in address.keys()” can traverse all keys.

Innovation Course | Basics of Python (Part 3)Innovation Course | Basics of Python (Part 3)

Be particularly cautious with the copy mechanism: direct assignment will link objects, while list() or copy() will create independent copies. All containers can nest storage, but only lists and dictionaries support content modification.

Innovation Course | Basics of Python (Part 3)

end

Who Are We?

WHO ARE WE?Since 2016, the Shanghai Municipal Education Commission and the Shanghai Municipal Science and Technology Commission have jointly established the “Shanghai Youth Science Innovation Practice Station” project, aiming to integrate high-quality resources from universities and research institutes, select and enroll some high school students in the city to study at the practice station, and connect various fields of scientific innovation carriers both inside and outside the school, bridging interdisciplinary and multi-dimensional courses, facilitating online and offline scientific inquiry topics with multi-dimensional evaluation, allowing students to broaden their scientific horizons, train their thinking methods, enrich their learning experiences, cultivate innovative spirit, enhance practical abilities, accumulate scientific literacy, and shape humanistic feelings.Currently, the “Shanghai Youth Science Innovation Practice Station” project has a total of 37 practice stations, including Fudan Computer, Jiaotong University Cybersecurity, Tongji Physics, East China Normal University Geography, and Shanghai Astronomical Observatory Astronomy, offering 14 categories of scientific innovation courses such as biology, medicine, chemistry, computer science, environment, mathematics, engineering optics, engineering mechanics, astronomy, horticulture, physics, geography, design, and electronic science and technology;Each practice station is composed of four practice points from experimental demonstration high schools at the municipal and district levels, youth activity centers (youth science stations), popular science venues, research institutes, and other units.There are currently 37 practice stations and 148 practice points.The practice station project enrolls about 4,440 high school students each year, further improving the scientific innovation practice education model through learning professional courses, dialogues with authoritative experts, hands-on experimental exploration, field visits, writing research papers, and on-site reporting and defense, to reserve talents for Shanghai to build a globally influential science and technology innovation center.

Leave a Comment