程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python basic notes

編輯:Python

Reference documents

Python Programming
windows python library

Identifiers and variables

Input and output

example —— Find triangle area :

import math
a = int(input())
b = int(input())
c = int(input())
p = (a + b + c) / 2
# '*' It means multiply ,math.sqrt It means open root
area = math.sqrt(p * (p - a) * (p - b) * (p - c))
print(" The side length of the triangle :", a, b, c, end=' ')
print(" The area of the triangle :", area)

example —— utilize turtle Draw Pentagram

# turtle Draw Pentagram 
import turtle
turtle.forward(200)
turtle.right(144)
turtle.forward(200)
turtle.right(144)
turtle.forward(200)
turtle.right(144)
turtle.forward(200)
turtle.right(144)
turtle.forward(200)
turtle.done()

Possible solutions :pycharm Yes turtle There are conflicts
find turtle.py,
You can be right turtle The source code of the library is modified as follows :
Comment out the original _ all_, Add the following :

# __all__ = (_tg_classes + _tg_screen_functions + _tg_turtle_functions +
# _tg_utilities + ['Terminator']) # + _math_functions)
__all__ = ['ScrolledCanvas', 'TurtleScreen', 'Screen', 'RawTurtle', 'Turtle', 'RawPen', 'Pen', 'Shape', 'Vec2D', 'back',
'backward', 'begin_fill', 'begin_poly', 'bk', 'addshape', 'bgcolor', 'bgpic', 'bye', 'clearscreen',
'colormode', 'delay', 'exitonclick', 'getcanvas', 'getshapes', 'listen', 'mainloop', 'mode', 'numinput',
'onkey', 'onkeypress', 'onkeyrelease', 'onscreenclick', 'ontimer', 'register_shape', 'resetscreen',
'screensize', 'setup', 'Terminator', 'setworldcoordinates', 'textinput', 'title', 'tracer', 'turtles',
'update', 'window_height', 'window_width', 'write_docstringdict', 'done', 'circle', 'clear', 'clearstamp',
'clearstamps', 'clone', 'color', 'degrees', 'distance', 'dot', 'down', 'end_fill', 'end_poly', 'fd',
'fillcolor', 'filling', 'forward', 'get_poly', 'getpen', 'getscreen', 'get_shapepoly', 'getturtle', 'goto',
'heading', 'hideturtle', 'home', 'ht', 'isdown', 'isvisible', 'left', 'lt', 'onclick', 'ondrag', 'onrelease',
'pd', 'pen', 'pencolor', 'pendown', 'pensize', 'penup', 'pos', 'position', 'pu', 'radians', 'right', 'reset',
'resizemode', 'rt', 'seth', 'setheading', 'setpos', 'setposition', 'settiltangle', 'setundobuffer', 'setx',
'sety', 'shape', 'shapesize', 'shapetransform', 'shearfactor', 'showturtle', 'speed', 'st', 'stamp', 'tilt',
'tiltangle', 'towards', 'turtlesize', 'undo', 'undobufferentries', 'up', 'width', 'write', 'xcor', 'ycor']

Built in conversion function

function







# Input n(n >= 10), seek 1+2+...+n The sum of the .
n=int(input())
s=sum(list(range(n+1)))
print(s)


# Produce the same number for each N digit 
a,b=input().split(',')
print(int(str(int(a))*int(b)))

Format output

To be continued

aggregate

aggregate (set) It's a kind of container , Element has no order , And the value of the element is not repeated . The literal value of the set is in curly brackets {}.










Dictionaries












  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved