in python you can_Python base

标签:

//this is my first day to study python, in order to review, every day i will make notes (2016/7/31)

1. In python , there are many bulit-in funcation. you can user follow to find out hou many built-in funcation:

dir(__builtins__)

if you want get BIF detail, you can use follow code:

help(……)    such as help(input),int()

2. In python, you should be care to indent, if not , it will appear a lots error.

such as follow ,because indent error ,it will appear an error:

temp = input(‘input a num you want:‘)

guess = int(temp)

if guess == 8:

print(‘you are right‘)

else:

print(‘you are wrong‘)

3. In python , when you define variable ,uppercase and lowercase is different.

such as:

temp = ‘roy‘

Temp = ‘wyg‘

temp and Temp is not same variable

4. In python , if you want to user ‘ in a string ,you can user escape charcters : \

such as:

print(‘Let\‘s go!‘)

5. In python , origin string is userful , maybe the follow result is not  you except

such as :

str = ‘c:\now\data‘

print(str)

result is :

c:

ow\data

you can solve this proble by str = r‘c:\now\data‘ ,this code is equal to str = ‘c:\\now\\data‘

when you print(str), the result will be c:\now\data

6. In python , if a string , you want to change row ,you can user ‘‘‘  ,if you not user ‘‘‘ and change row ,it will appear an error

such as:

str = ‘‘‘this

is

me‘‘‘

print(str)

the result is :

this

is

me

7. import module , such as if you want  a rand num , range is 1-10 and type is int ,how to achieve it

import random

randnum = random.randint(1,10)

标签:

To run Python in Docker, you can follow these steps: 1. Create a Dockerfile: Start by creating a file named `Dockerfile` in your project directory. 2. Define the base image: In the Dockerfile, specify the base image you want to use. For example, you can use the official Python image from Docker Hub: ``` FROM python:3 ``` 3. Copy your code: Use the `COPY` instruction in the Dockerfile to copy your Python code into the container. Let's assume your code is in a file named `app.py`: ``` COPY app.py /app/app.py ``` 4. Set the working directory: Use the `WORKDIR` instruction to set the working directory inside the container: ``` WORKDIR /app ``` 5. Install dependencies: If your Python code has any dependencies, you need to install them in the container. You can do this by adding a `requirements.txt` file to your project and running `pip install` inside the Dockerfile: ``` COPY requirements.txt /app/requirements.txt RUN pip install -r requirements.txt ``` 6. Specify the command to run: Finally, use the `CMD` instruction to define the command that should be executed when the container starts. In this case, we want to run the `app.py` file: ``` CMD ["python", "app.py"] ``` 7. Build and run the Docker image: Open a terminal, navigate to your project directory, and run the following commands: ``` docker build -t my-python-app . docker run my-python-app ``` This will build a Docker image based on your Dockerfile and then run a container using that image. The Python code in `app.py` should now be executed inside the Docker container.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值