Python Basics

本文深入探讨了Python编程的基础语法、数据类型、数学运算、注释、字符串操作、条件语句、函数定义、列表与字典等核心概念,同时介绍了Python在数据处理、文件I/O、日期时间操作、条件判断、循环结构、字符串方法、类与对象等方面的应用。通过实践案例和代码示例,旨在为读者提供全面的Python编程技能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Python Syntax

  • Data Type
  • Indention
  • Math Operation
  • Comment

String and console output

  • 转移字符\
  • Access by index
  • Strig Method
  • str()
  • Not Notation
  • Printing Strings
  • print variables

Advanced printing

  • string concatenation
  • explicit string conversion
  • string formatting with %

Review

  • string creating, three way: ”, ” “, str()
  • string method: upper(), lower()
  • print string

Datetime

  • datetime.now
  • now.year
  • hot date
  • pretty date

Conditionals and flow control

  • booleans
  • comparison operator
  • boolean operator, not first, and next, or last
  • if, else,elif

Summary: comparator, boolean operator, conditional statement

Functions

  • Function Junctions
  • Calling Function
  • Agruments
  • Function calling Functions
  • import
  • built in functions

List and Dictionary

list

  • Access by index
  • Assignment
  • Late arrival(append) and list length
  • Slicing
  • Search and insert
  • For one and all
  • sort

Dictionary

  • key accessing
  • new entries
  • del by keyword (general cases)
  • remove by value (list notation method)

operation with list

  • list as argument
  • string looping

Lists and funcstions

  • .pop(index),.remove(item)
  • range
  • iterating a list in a function
  • using string in list in function

Battleship exercise

  • ” “.join(letters)
  • from random import randint

Loops

  • while loop
  • for strings
  • for list
  • for dictionary
  • eumuerate
  • zip

Practice

  • Fun with numbers
  • String it together(access, reverse, split and join)
  • Listing your problems
  • remove duplicates

Advanced Python Features

  • items(),values(),keys()
  • list comprehension using for/in and if
  • list slicing
  • reverse a list, lst[::-1]
  • Anonymous Functions lambda x: x%3 ==0
  • Filter, filter(lambda, lst)

bitwise operation

  • << and >>
  • &
  • |
  • ^
  • 0b101, bin(0b101)

Classes

To be sepcified
- Class basics: class NewName(object):
- Class instance
- Class member variable : belongs to class
- Calling member variables
- Initializing a class: __init__
- Member function
- Overloading

File input/Output

  • f = open(“text.txt”,’r’) : ‘r’,’w’,’r+’,’a’
  • f.close()
  • with open(‘text.txt’,’w’) as f: ….. it will close the file for us
  • f.closed
  • f.readline() read text line-by-line
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值