Cd có nghĩa là gì trong Python?

Trong CSE 140, bạn sử dụng hai công cụ để chạy chương trình Python. IDLE và shell dòng lệnh. Đây là một hướng dẫn nhỏ trong việc sử dụng shell

Trình bao dòng lệnh, đôi khi được gọi là dấu nhắc lệnh hoặc thiết bị đầu cuối, là một công cụ cho phép bạn điều khiển máy tính của mình chỉ bằng các lệnh văn bản. Nó cung cấp rất nhiều sức mạnh và sự đơn giản [đơn giản khác với dễ sử dụng]

Giống như với trình duyệt tệp đồ họa như Finder hoặc Windows Explorer, có một "thư mục hiện tại" mà bạn hiện đang làm việc trong đó. ["Thư mục" và "thư mục" là từ đồng nghĩa. ] Bạn có thể đưa ra các lệnh hoạt động trong thư mục đó hoặc bạn có thể thay đổi thư mục hiện tại

Hướng dẫn này trình bày một bản ghi ví dụ về cách sử dụng trình bao cho các máy Unix [Mac/Linux] và Windows. Bảng điểm giả định rằng học sinh đã cài đặt Bản phân phối Enth think Python như được mô tả trong trang Tài nguyên Máy tính và đã sử dụng các chương trình khác như Finder hoặc Windows Explorer để tải bài tập về nhà của mình vào một thư mục. Khi bạn chạy các lệnh tương tự, có thể có một chút khác biệt so với bản ghi ví dụ, chẳng hạn như số lượng, tên và thời gian của tệp

Xem phần phù hợp với bạn

Mac/Linux

Dưới đây là hầu hết các lệnh bạn sẽ cần sử dụng

  • pwd - in tên đường dẫn tuyệt đối của thư mục làm việc hiện tại của bạn
  • thư mục cd - thay đổi thư mục làm việc của bạn thành thư mục đã cho
  • đĩa CD. - thay đổi thư mục làm việc của bạn thành thư mục gốc của thư mục làm việc hiện tại
  • ls - liệt kê nội dung của thư mục hiện tại ["ls" là viết tắt của "list"]
  • python - chạy trình thông dịch Python
  • chương trình trăn. py - chạy chương trình Python được lưu trữ trong chương trình. tập tin py

Bạn có thể mở trình bao dòng lệnh bằng cách chạy chương trình đầu cuối

Trong bảng điểm ví dụ dưới đây, văn bản như C. \Users\Me> là dấu nhắc mà tại đó người dùng gõ lệnh. Văn bản in đậm được người dùng nhập và văn bản không in đậm được in bởi shell dòng lệnh. Cũng lưu ý rằng trong bảng điểm ví dụ này, nhiều đầu ra không liên quan đã bị loại bỏ để nhấn mạnh thông tin quan trọng

Dòng lệnh là một cách tương tác thân mật hơn với máy tính của bạn [hơn là Finder trên Mac hoặc Explorer trên Windows]. Chúng tôi đã [có thể] sử dụng nó để cài đặt Python 3, pip, virtualenv và virtualenvwrapper trong quá trình định hướng [nếu bạn chưa làm điều đó, hãy làm điều đó ngay bây giờ]. Bạn cũng có thể nghe mọi người gọi dòng lệnh là shell, Terminal [trên Mac] hoặc PowerShell [trên Windows]

Tôi đã biên dịch rất nhiều lệnh shell phổ biến. Bây giờ tôi sẽ không nhắc lại tất cả chúng ở đây, nhưng hãy nhớ rằng

# This will make your computer mad because it can't add a string to an integer.
print['10' + 10]

# Strings and integers are different data types!
# Cast your string into an int[ger]
print[int['10'] + 10]
# Output is 20.

# Or cast your int into a string:
print ['10' + str[10]]
# Output is 1010

print['Hello' + str[10]]
# This gives you "Hello10" back.
1,
# This will make your computer mad because it can't add a string to an integer.
print['10' + 10]

# Strings and integers are different data types!
# Cast your string into an int[ger]
print[int['10'] + 10]
# Output is 20.

# Or cast your int into a string:
print ['10' + str[10]]
# Output is 1010

print['Hello' + str[10]]
# This gives you "Hello10" back.
2,
# This will make your computer mad because it can't add a string to an integer.
print['10' + 10]

# Strings and integers are different data types!
# Cast your string into an int[ger]
print[int['10'] + 10]
# Output is 20.

# Or cast your int into a string:
print ['10' + str[10]]
# Output is 1010

print['Hello' + str[10]]
# This gives you "Hello10" back.
3,
# This will make your computer mad because it can't add a string to an integer.
print['10' + 10]

# Strings and integers are different data types!
# Cast your string into an int[ger]
print[int['10'] + 10]
# Output is 20.

# Or cast your int into a string:
print ['10' + str[10]]
# Output is 1010

print['Hello' + str[10]]
# This gives you "Hello10" back.
0 thực sự hữu ích khi bạn di chuyển xung quanh máy tính của mình bằng dòng lệnh. Một vài điều khác cần ghi nhớ

  • Bạn có thể thêm cờ vào các lệnh để hướng dẫn shell thực hiện những việc cụ thể hoặc cấu trúc đầu ra của nó theo một cách cụ thể. Một vài cờ hữu ích để thêm vào lệnh
    # This will make your computer mad because it can't add a string to an integer.
    print['10' + 10]
    
    # Strings and integers are different data types!
    # Cast your string into an int[ger]
    print[int['10'] + 10]
    # Output is 20.
    
    # Or cast your int into a string:
    print ['10' + str[10]]
    # Output is 1010
    
    print['Hello' + str[10]]
    # This gives you "Hello10" back.
    
    2
    • # This will make your computer mad because it can't add a string to an integer.
      print['10' + 10]
      
      # Strings and integers are different data types!
      # Cast your string into an int[ger]
      print[int['10'] + 10]
      # Output is 20.
      
      # Or cast your int into a string:
      print ['10' + str[10]]
      # Output is 1010
      
      print['Hello' + str[10]]
      # This gives you "Hello10" back.
      
      2. hiển thị thêm thông tin về các tệp và thư mục của bạn [bạn sẽ nhập nó dưới dạng
      # This will make your computer mad because it can't add a string to an integer.
      print['10' + 10]
      
      # Strings and integers are different data types!
      # Cast your string into an int[ger]
      print[int['10'] + 10]
      # Output is 20.
      
      # Or cast your int into a string:
      print ['10' + str[10]]
      # Output is 1010
      
      print['Hello' + str[10]]
      # This gives you "Hello10" back.
      
      3 trong trình bao của mình]
    • # This will make your computer mad because it can't add a string to an integer.
      print['10' + 10]
      
      # Strings and integers are different data types!
      # Cast your string into an int[ger]
      print[int['10'] + 10]
      # Output is 20.
      
      # Or cast your int into a string:
      print ['10' + str[10]]
      # Output is 1010
      
      print['Hello' + str[10]]
      # This gives you "Hello10" back.
      
      4. làm cho các số kích thước tệp được hiển thị có thể đọc được
    • # This will make your computer mad because it can't add a string to an integer.
      print['10' + 10]
      
      # Strings and integers are different data types!
      # Cast your string into an int[ger]
      print[int['10'] + 10]
      # Output is 20.
      
      # Or cast your int into a string:
      print ['10' + str[10]]
      # Output is 1010
      
      print['Hello' + str[10]]
      # This gives you "Hello10" back.
      
      5. tất cả, hiển thị cho bạn các tệp ẩn, thường là những thứ quan trọng mà máy tính của bạn không muốn bạn xử lý
    • Bạn có thể sử dụng một loạt cờ cùng nhau
      # This will make your computer mad because it can't add a string to an integer.
      print['10' + 10]
      
      # Strings and integers are different data types!
      # Cast your string into an int[ger]
      print[int['10'] + 10]
      # Output is 20.
      
      # Or cast your int into a string:
      print ['10' + str[10]]
      # Output is 1010
      
      print['Hello' + str[10]]
      # This gives you "Hello10" back.
      
      6 hoặc
      # This will make your computer mad because it can't add a string to an integer.
      print['10' + 10]
      
      # Strings and integers are different data types!
      # Cast your string into an int[ger]
      print[int['10'] + 10]
      # Output is 20.
      
      # Or cast your int into a string:
      print ['10' + str[10]]
      # Output is 1010
      
      print['Hello' + str[10]]
      # This gives you "Hello10" back.
      
      7
  • Một vài lệnh
    # This will make your computer mad because it can't add a string to an integer.
    print['10' + 10]
    
    # Strings and integers are different data types!
    # Cast your string into an int[ger]
    print[int['10'] + 10]
    # Output is 20.
    
    # Or cast your int into a string:
    print ['10' + str[10]]
    # Output is 1010
    
    print['Hello' + str[10]]
    # This gives you "Hello10" back.
    
    8 hữu ích
    • # This will make your computer mad because it can't add a string to an integer.
      print['10' + 10]
      
      # Strings and integers are different data types!
      # Cast your string into an int[ger]
      print[int['10'] + 10]
      # Output is 20.
      
      # Or cast your int into a string:
      print ['10' + str[10]]
      # Output is 1010
      
      print['Hello' + str[10]]
      # This gives you "Hello10" back.
      
      0 di chuyển bạn “lên” một thư mục
    • Khi bạn thấy ~ trong terminal, điều đó có nghĩa là bạn đang ở trong thư mục chính của mình
    • # Store things in variables!
      name = "Dennis"
      print["Hello, " + name]
      
      # Don't use spaces in variable names
      last_name = Soma # This is okay
      last name = Soma # This will not work
      lastName = Soma # Works!
      
      
      # Store user input in a variable!
      name = input["What's your name?"]
      print["Hello, " + name]
      
      0. đưa bạn trực tiếp đến thư mục nhà của bạn
    • # Store things in variables!
      name = "Dennis"
      print["Hello, " + name]
      
      # Don't use spaces in variable names
      last_name = Soma # This is okay
      last name = Soma # This will not work
      lastName = Soma # Works!
      
      
      # Store user input in a variable!
      name = input["What's your name?"]
      print["Hello, " + name]
      
      1. đưa bạn trực tiếp đến thư mục Tải xuống của bạn
    • # Store things in variables!
      name = "Dennis"
      print["Hello, " + name]
      
      # Don't use spaces in variable names
      last_name = Soma # This is okay
      last name = Soma # This will not work
      lastName = Soma # Works!
      
      
      # Store user input in a variable!
      name = input["What's your name?"]
      print["Hello, " + name]
      
      2. nó sẽ tự động điền đường dẫn đến thư mục đó. Điều này chỉ hoạt động trên máy Mac
  • Nếu dòng lệnh của bạn đang chạy thứ gì đó không nên chạy, hãy sử dụng
    # Store things in variables!
    name = "Dennis"
    print["Hello, " + name]
    
    # Don't use spaces in variable names
    last_name = Soma # This is okay
    last name = Soma # This will not work
    lastName = Soma # Works!
    
    
    # Store user input in a variable!
    name = input["What's your name?"]
    print["Hello, " + name]
    
    3 để thoát/thoát
  • # Store things in variables!
    name = "Dennis"
    print["Hello, " + name]
    
    # Don't use spaces in variable names
    last_name = Soma # This is okay
    last name = Soma # This will not work
    lastName = Soma # Works!
    
    
    # Store user input in a variable!
    name = input["What's your name?"]
    print["Hello, " + name]
    
    4 sẽ làm chính xác như âm thanh của nó;
  • Tên tệp và thư mục phải được gõ chính xác.
    # Store things in variables!
    name = "Dennis"
    print["Hello, " + name]
    
    # Don't use spaces in variable names
    last_name = Soma # This is okay
    last name = Soma # This will not work
    lastName = Soma # Works!
    
    
    # Store user input in a variable!
    name = input["What's your name?"]
    print["Hello, " + name]
    
    5 và
    # Store things in variables!
    name = "Dennis"
    print["Hello, " + name]
    
    # Don't use spaces in variable names
    last_name = Soma # This is okay
    last name = Soma # This will not work
    lastName = Soma # Works!
    
    
    # Store user input in a variable!
    name = input["What's your name?"]
    print["Hello, " + name]
    
    6 khác nhau [bạn có thể muốn sử dụng cái sau]

Khám phá thư mục & tệp

Trong lớp, chúng tôi đã tải xuống một tệp từ Slack để kiểm tra các lệnh mới của mình. Giải nén tệp zip, sau đó

  1. # This will make your computer mad because it can't add a string to an integer.
    print['10' + 10]
    
    # Strings and integers are different data types!
    # Cast your string into an int[ger]
    print[int['10'] + 10]
    # Output is 20.
    
    # Or cast your int into a string:
    print ['10' + str[10]]
    # Output is 1010
    
    print['Hello' + str[10]]
    # This gives you "Hello10" back.
    
    1 để xem bạn đang ở đâu
  2. # This will make your computer mad because it can't add a string to an integer.
    print['10' + 10]
    
    # Strings and integers are different data types!
    # Cast your string into an int[ger]
    print[int['10'] + 10]
    # Output is 20.
    
    # Or cast your int into a string:
    print ['10' + str[10]]
    # Output is 1010
    
    print['Hello' + str[10]]
    # This gives you "Hello10" back.
    
    2 xem có gì nào
  3. # Store things in variables!
    name = "Dennis"
    print["Hello, " + name]
    
    # Don't use spaces in variable names
    last_name = Soma # This is okay
    last name = Soma # This will not work
    lastName = Soma # Works!
    
    
    # Store user input in a variable!
    name = input["What's your name?"]
    print["Hello, " + name]
    
    1 để thay đổi thư mục thành thư mục Tải xuống của bạn
  4. # This will make your computer mad because it can't add a string to an integer.
    print['10' + 10]
    
    # Strings and integers are different data types!
    # Cast your string into an int[ger]
    print[int['10'] + 10]
    # Output is 20.
    
    # Or cast your int into a string:
    print ['10' + str[10]]
    # Output is 1010
    
    print['Hello' + str[10]]
    # This gives you "Hello10" back.
    
    70
  5. # This will make your computer mad because it can't add a string to an integer.
    print['10' + 10]
    
    # Strings and integers are different data types!
    # Cast your string into an int[ger]
    print[int['10'] + 10]
    # Output is 20.
    
    # Or cast your int into a string:
    print ['10' + str[10]]
    # Output is 1010
    
    print['Hello' + str[10]]
    # This gives you "Hello10" back.
    
    1 để kiểm tra bạn đang ở đúng nơi
  6. # This will make your computer mad because it can't add a string to an integer.
    print['10' + 10]
    
    # Strings and integers are different data types!
    # Cast your string into an int[ger]
    print[int['10'] + 10]
    # Output is 20.
    
    # Or cast your int into a string:
    print ['10' + str[10]]
    # Output is 1010
    
    print['Hello' + str[10]]
    # This gives you "Hello10" back.
    
    72 để xem nội dung của tệp
  7. Tuy nhiên, việc nhập tên tệp cực kỳ khó chịu - hãy viết
    # This will make your computer mad because it can't add a string to an integer.
    print['10' + 10]
    
    # Strings and integers are different data types!
    # Cast your string into an int[ger]
    print[int['10'] + 10]
    # Output is 20.
    
    # Or cast your int into a string:
    print ['10' + str[10]]
    # Output is 1010
    
    print['Hello' + str[10]]
    # This gives you "Hello10" back.
    
    73 rồi nhấn TAB để tự động điền tên tệp

TIỀN BOA. Nếu nhấn TAB không tự động hoàn thành thư mục hoặc tên tệp của bạn, thì bạn có thể cần nhập thêm một vài chữ cái để phân biệt thư mục hoặc tệp mà bạn muốn nói

Ngoài ra, hãy đảm bảo rằng tính năng tự động điền đã cung cấp cho bạn TOÀN BỘ thư mục hoặc tên tệp. Đôi khi, bạn sẽ phải nhập lại chữ cái tiếp theo và nhấn TAB, đặc biệt nếu có khoảng trắng trong tên tệp của bạn

KHÔNG ĐẶT CHỖ DẠNG HOẶC DẤU DẤU TRONG TÊN TỆP CỦA BẠN

Bên cạnh việc sử dụng

# This will make your computer mad because it can't add a string to an integer.
print['10' + 10]

# Strings and integers are different data types!
# Cast your string into an int[ger]
print[int['10'] + 10]
# Output is 20.

# Or cast your int into a string:
print ['10' + str[10]]
# Output is 1010

print['Hello' + str[10]]
# This gives you "Hello10" back.
74 để xem toàn bộ tệp, bạn cũng có thể lấy đỉnh ở đầu hoặc cuối tệp. [CHỈ OS X]

  • # This will make your computer mad because it can't add a string to an integer.
    print['10' + 10]
    
    # Strings and integers are different data types!
    # Cast your string into an int[ger]
    print[int['10'] + 10]
    # Output is 20.
    
    # Or cast your int into a string:
    print ['10' + str[10]]
    # Output is 1010
    
    print['Hello' + str[10]]
    # This gives you "Hello10" back.
    
    75. xem 20 dòng đầu tiên;
  • # This will make your computer mad because it can't add a string to an integer.
    print['10' + 10]
    
    # Strings and integers are different data types!
    # Cast your string into an int[ger]
    print[int['10'] + 10]
    # Output is 20.
    
    # Or cast your int into a string:
    print ['10' + str[10]]
    # Output is 1010
    
    print['Hello' + str[10]]
    # This gives you "Hello10" back.
    
    76. sử dụng đuôi để xem phần cuối của tệp;

Săn tìm kho báu

Vì vậy, chúng tôi đã tìm thấy một kho báu tuyệt vời trong lớp. Điểm rút ra QUAN TRỌNG NHẤT từ bài tập này là bạn nên sử dụng TAB để tự động điền tên thư mục và tệp càng nhiều càng tốt. Xem các mẹo ở trên về cách sử dụng tính năng tự động điền/TAB

  1. Điều hướng đến vị trí tệp zip đã tải xuống [và hy vọng được trích xuất] của bạn
  2. # This will make your computer mad because it can't add a string to an integer.
    print['10' + 10]
    
    # Strings and integers are different data types!
    # Cast your string into an int[ger]
    print[int['10'] + 10]
    # Output is 20.
    
    # Or cast your int into a string:
    print ['10' + str[10]]
    # Output is 1010
    
    print['Hello' + str[10]]
    # This gives you "Hello10" back.
    
    78 để xem hướng dẫn truy tìm kho báu
  3. Bạn sẽ nhận thấy rằng tên thư mục và tệp rất khó hiểu. Sử dụng TAB/tự động điền để máy tính của bạn thực hiện mọi công việc khó khăn cho bạn
    • # This will make your computer mad because it can't add a string to an integer.
      print['10' + 10]
      
      # Strings and integers are different data types!
      # Cast your string into an int[ger]
      print[int['10'] + 10]
      # Output is 20.
      
      # Or cast your int into a string:
      print ['10' + str[10]]
      # Output is 1010
      
      print['Hello' + str[10]]
      # This gives you "Hello10" back.
      
      79 cho biết rằng ký tự khoảng trắng thực sự là một phần của tên bạn đang tìm kiếm.
      # This will make your computer mad because it can't add a string to an integer.
      print['10' + 10]
      
      # Strings and integers are different data types!
      # Cast your string into an int[ger]
      print[int['10'] + 10]
      # Output is 20.
      
      # Or cast your int into a string:
      print ['10' + str[10]]
      # Output is 1010
      
      print['Hello' + str[10]]
      # This gives you "Hello10" back.
      
      79 là một ký tự thoát – bởi vì khoảng trắng có thể có ý nghĩa khác trên Terminal, sử dụng
      # This will make your computer mad because it can't add a string to an integer.
      print['10' + 10]
      
      # Strings and integers are different data types!
      # Cast your string into an int[ger]
      print[int['10'] + 10]
      # Output is 20.
      
      # Or cast your int into a string:
      print ['10' + str[10]]
      # Output is 1010
      
      print['Hello' + str[10]]
      # This gives you "Hello10" back.
      
      79 trước khoảng trắng để Terminal biết rằng bạn thực sự có ý đó. Bạn cũng sẽ thấy cấu trúc này xuất hiện cùng với các “ký tự đặc biệt” khác [không chỉ khoảng trắng]

TIỀN BOA. Sử dụng ↑ và ↓ trên bàn phím của bạn để di chuyển qua các lệnh khác mà bạn đã nhập trên dòng lệnh

Các lệnh thú vị khác

  • # This will make your computer mad because it can't add a string to an integer.
    print['10' + 10]
    
    # Strings and integers are different data types!
    # Cast your string into an int[ger]
    print[int['10'] + 10]
    # Output is 20.
    
    # Or cast your int into a string:
    print ['10' + str[10]]
    # Output is 1010
    
    print['Hello' + str[10]]
    # This gives you "Hello10" back.
    
    82. cho phép bạn tìm kiếm một bộ ký tự cụ thể bên trong tệp [CHỈ OS X]
    • # This will make your computer mad because it can't add a string to an integer.
      print['10' + 10]
      
      # Strings and integers are different data types!
      # Cast your string into an int[ger]
      print[int['10'] + 10]
      # Output is 20.
      
      # Or cast your int into a string:
      print ['10' + str[10]]
      # Output is 1010
      
      print['Hello' + str[10]]
      # This gives you "Hello10" back.
      
      83
    • # This will make your computer mad because it can't add a string to an integer.
      print['10' + 10]
      
      # Strings and integers are different data types!
      # Cast your string into an int[ger]
      print[int['10'] + 10]
      # Output is 20.
      
      # Or cast your int into a string:
      print ['10' + str[10]]
      # Output is 1010
      
      print['Hello' + str[10]]
      # This gives you "Hello10" back.
      
      84. tìm kiếm phân biệt chữ hoa chữ thường
    • # This will make your computer mad because it can't add a string to an integer.
      print['10' + 10]
      
      # Strings and integers are different data types!
      # Cast your string into an int[ger]
      print[int['10'] + 10]
      # Output is 20.
      
      # Or cast your int into a string:
      print ['10' + str[10]]
      # Output is 1010
      
      print['Hello' + str[10]]
      # This gives you "Hello10" back.
      
      85
    • # This will make your computer mad because it can't add a string to an integer.
      print['10' + 10]
      
      # Strings and integers are different data types!
      # Cast your string into an int[ger]
      print[int['10'] + 10]
      # Output is 20.
      
      # Or cast your int into a string:
      print ['10' + str[10]]
      # Output is 1010
      
      print['Hello' + str[10]]
      # This gives you "Hello10" back.
      
      86. điều này tìm kiếm tất cả các tệp trong thư mục được chỉ định cho cụm từ tìm kiếm của bạn
    • Lưu ý rằng cụm từ tìm kiếm phân biệt chữ hoa chữ thường
  • # This will make your computer mad because it can't add a string to an integer.
    print['10' + 10]
    
    # Strings and integers are different data types!
    # Cast your string into an int[ger]
    print[int['10'] + 10]
    # Output is 20.
    
    # Or cast your int into a string:
    print ['10' + str[10]]
    # Output is 1010
    
    print['Hello' + str[10]]
    # This gives you "Hello10" back.
    
    87 là PowerShell tương đương với grep [CHỈ dành cho Windows]
    • # This will make your computer mad because it can't add a string to an integer.
      print['10' + 10]
      
      # Strings and integers are different data types!
      # Cast your string into an int[ger]
      print[int['10'] + 10]
      # Output is 20.
      
      # Or cast your int into a string:
      print ['10' + str[10]]
      # Output is 1010
      
      print['Hello' + str[10]]
      # This gives you "Hello10" back.
      
      88
    • # This will make your computer mad because it can't add a string to an integer.
      print['10' + 10]
      
      # Strings and integers are different data types!
      # Cast your string into an int[ger]
      print[int['10'] + 10]
      # Output is 20.
      
      # Or cast your int into a string:
      print ['10' + str[10]]
      # Output is 1010
      
      print['Hello' + str[10]]
      # This gives you "Hello10" back.
      
      89
  • # This will make your computer mad because it can't add a string to an integer.
    print['10' + 10]
    
    # Strings and integers are different data types!
    # Cast your string into an int[ger]
    print[int['10'] + 10]
    # Output is 20.
    
    # Or cast your int into a string:
    print ['10' + str[10]]
    # Output is 1010
    
    print['Hello' + str[10]]
    # This gives you "Hello10" back.
    
    60. xem mục nhập thủ công cho lệnh đó. Bán tại.
    # This will make your computer mad because it can't add a string to an integer.
    print['10' + 10]
    
    # Strings and integers are different data types!
    # Cast your string into an int[ger]
    print[int['10'] + 10]
    # Output is 20.
    
    # Or cast your int into a string:
    print ['10' + str[10]]
    # Output is 1010
    
    print['Hello' + str[10]]
    # This gives you "Hello10" back.
    
    61
    • sử dụng
      # This will make your computer mad because it can't add a string to an integer.
      print['10' + 10]
      
      # Strings and integers are different data types!
      # Cast your string into an int[ger]
      print[int['10'] + 10]
      # Output is 20.
      
      # Or cast your int into a string:
      print ['10' + str[10]]
      # Output is 1010
      
      print['Hello' + str[10]]
      # This gives you "Hello10" back.
      
      62 để thoát khỏi sách hướng dẫn, vì nó thật kinh khủng
  • # This will make your computer mad because it can't add a string to an integer.
    print['10' + 10]
    
    # Strings and integers are different data types!
    # Cast your string into an int[ger]
    print[int['10'] + 10]
    # Output is 20.
    
    # Or cast your int into a string:
    print ['10' + str[10]]
    # Output is 1010
    
    print['Hello' + str[10]]
    # This gives you "Hello10" back.
    
    63. lấy số dòng cho tệp đã cho [CHỈ OS X]

  • # This will make your computer mad because it can't add a string to an integer.
    print['10' + 10]
    
    # Strings and integers are different data types!
    # Cast your string into an int[ger]
    print[int['10'] + 10]
    # Output is 20.
    
    # Or cast your int into a string:
    print ['10' + str[10]]
    # Output is 1010
    
    print['Hello' + str[10]]
    # This gives you "Hello10" back.
    
    64. lấy số dòng cho tệp đã cho [CHỈ dành cho Windows]

Đường ống một cách kết nối các lệnh khác nhau với nhau trên thiết bị đầu cuối

  • # This will make your computer mad because it can't add a string to an integer.
    print['10' + 10]
    
    # Strings and integers are different data types!
    # Cast your string into an int[ger]
    print[int['10'] + 10]
    # Output is 20.
    
    # Or cast your int into a string:
    print ['10' + str[10]]
    # Output is 1010
    
    print['Hello' + str[10]]
    # This gives you "Hello10" back.
    
    65. hiển thị số dòng của đầu ra của
    # This will make your computer mad because it can't add a string to an integer.
    print['10' + 10]
    
    # Strings and integers are different data types!
    # Cast your string into an int[ger]
    print[int['10'] + 10]
    # Output is 20.
    
    # Or cast your int into a string:
    print ['10' + str[10]]
    # Output is 1010
    
    print['Hello' + str[10]]
    # This gives you "Hello10" back.
    
    66 [chứ không phải toàn bộ tệp]
  • # This will make your computer mad because it can't add a string to an integer.
    print['10' + 10]
    
    # Strings and integers are different data types!
    # Cast your string into an int[ger]
    print[int['10'] + 10]
    # Output is 20.
    
    # Or cast your int into a string:
    print ['10' + str[10]]
    # Output is 1010
    
    print['Hello' + str[10]]
    # This gives you "Hello10" back.
    
    67. Windows tương đương ở trên
  • Thông tin thêm về đường ống

Cách viết và chạy tập lệnh Python

  1. Mở Atom và tạo một tệp mới. Tệp > Lưu “giới thiệu. py”
  2. Trên dòng lệnh,
    # This will make your computer mad because it can't add a string to an integer.
    print['10' + 10]
    
    # Strings and integers are different data types!
    # Cast your string into an int[ger]
    print[int['10'] + 10]
    # Output is 20.
    
    # Or cast your int into a string:
    print ['10' + str[10]]
    # Output is 1010
    
    print['Hello' + str[10]]
    # This gives you "Hello10" back.
    
    8 vào thư mục mà bạn đã lưu phần giới thiệu. py
  3. Hãy chỉnh sửa phần giới thiệu. py trong Atom để tập lệnh của chúng tôi thực sự làm mọi việc

Nhớ lại. Chúng tôi sử dụng

# This will make your computer mad because it can't add a string to an integer.
print['10' + 10]

# Strings and integers are different data types!
# Cast your string into an int[ger]
print[int['10'] + 10]
# Output is 20.

# Or cast your int into a string:
print ['10' + str[10]]
# Output is 1010

print['Hello' + str[10]]
# This gives you "Hello10" back.
69 để viết nhận xét trong mã của mình

in ấn

# This will make your computer mad because it can't add a string to an integer.
print['10' + 10]

# Strings and integers are different data types!
# Cast your string into an int[ger]
print[int['10'] + 10]
# Output is 20.

# Or cast your int into a string:
print ['10' + str[10]]
# Output is 1010

print['Hello' + str[10]]
# This gives you "Hello10" back.
6

Số học & Đúc

# This will make your computer mad because it can't add a string to an integer.
print['10' + 10]

# Strings and integers are different data types!
# Cast your string into an int[ger]
print[int['10'] + 10]
# Output is 20.

# Or cast your int into a string:
print ['10' + str[10]]
# Output is 1010

print['Hello' + str[10]]
# This gives you "Hello10" back.

Biến & Lấy đầu vào

# Store things in variables!
name = "Dennis"
print["Hello, " + name]

# Don't use spaces in variable names
last_name = Soma # This is okay
last name = Soma # This will not work
lastName = Soma # Works!


# Store user input in a variable!
name = input["What's your name?"]
print["Hello, " + name]

câu lệnh if

# This will make your computer mad because it can't add a string to an integer.
print['10' + 10]

# Strings and integers are different data types!
# Cast your string into an int[ger]
print[int['10'] + 10]
# Output is 20.

# Or cast your int into a string:
print ['10' + str[10]]
# Output is 1010

print['Hello' + str[10]]
# This gives you "Hello10" back.
7

Bây giờ, hãy nhập

# This will make your computer mad because it can't add a string to an integer.
print['10' + 10]

# Strings and integers are different data types!
# Cast your string into an int[ger]
print[int['10'] + 10]
# Output is 20.

# Or cast your int into a string:
print ['10' + str[10]]
# Output is 1010

print['Hello' + str[10]]
# This gives you "Hello10" back.
00 vào trình bao của bạn để chạy tập lệnh Python đầu tiên của bạn. Nếu có lỗi trong tập lệnh Python của bạn, đừng lo lắng. Vỏ của bạn chắc chắn sẽ cho bạn biết

Lỗi thông thường

TIỀN BOA. Hãy chú ý đến các lỗi bạn gặp phải khi chạy tập lệnh Python. Terminal/Babun có thể sẽ cho bạn biết chính xác bạn đã sai ở đâu [số dòng hoặc ký tự gần lỗi nhất]

cd có nghĩa là gì trong mã hóa?

Cung cấp liên tục [CD] là một phương pháp phân phối phần mềm trong đó các nhóm phát triển sản xuất và kiểm tra mã trong các chu kỳ ngắn nhưng liên tục, thường có mức độ tự động hóa cao, để cải thiện chất lượng phần mềm.

Việc sử dụng dữ liệu cd ~/ là gì?

Nó được sử dụng để thay đổi thư mục làm việc hiện tại. Trong ví dụ trên, chúng tôi đã kiểm tra số lượng thư mục trong thư mục chính của mình và di chuyển vào bên trong thư mục Tài liệu bằng cách sử dụng lệnh cd Documents

Bạn có thể cd trong tập lệnh Python không?

Bạn có thể thay đổi thư mục hoặc cd trong Python bằng mô-đun os . Đầu vào là đường dẫn tương đối/tuyệt đối của thư mục bạn muốn chuyển sang.

cd có nghĩa là gì trong thiết bị đầu cuối?

cd hoặc thay đổi thư mục . Lệnh cd nhận một đối số, thường là tên của thư mục bạn muốn chuyển đến, vì vậy lệnh đầy đủ là cd your-directory. Trong thiết bị đầu cuối, gõ. $ ls.

Chủ Đề