Python ljust() 方法左對齊字符串並用填充字符填充剩餘的空格。此方法返回一個左對齊並填充填充字符的新字符串。
簽名
ljust(width[, fillchar])
參數
- width: 給定字符串的寬度。
- fillchar:characters 填充字符串中的剩餘空間。它是可選的。
返回
它返回一個左對齊的字符串。
讓我們看一些 ljust() 方法的例子來理解它的函數。
Python 字符串 ljust() 方法示例 1
# Python ljust() method example
# Variable declaration
str = 'Javatpoint'
# Calling function
str = str.ljust(20)
# Displaying result
print(str)
輸出:
J | a | v | a | t | p | o | i | n | t |
Python 字符串 ljust() 方法示例 2
# Python ljust() method example
# Variable declaration
str = 'Javatpoint'
# Calling function
str = str.ljust(15,"$")
# Displaying result
print(str)
輸出:
J | a | v | a | t | p | o | i | n | t | $ | $ | $ | $ | $ |
相關用法
- Python String lstrip()用法及代碼示例
- Python String lower()用法及代碼示例
- Python String Center()用法及代碼示例
- Python String isnumeric()用法及代碼示例
- Python String join()用法及代碼示例
- Python String isalnum()用法及代碼示例
- Python String rsplit()用法及代碼示例
- Python String startswith()用法及代碼示例
- Python String upper()用法及代碼示例
- Python String splitlines()用法及代碼示例
- Python String isprintable()用法及代碼示例
- Python String translate()用法及代碼示例
- Python String split()用法及代碼示例
- Python String format_map()用法及代碼示例
- Python String zfill()用法及代碼示例
- Python String isspace()用法及代碼示例
- Python String Encode()用法及代碼示例
- Python String endswith()用法及代碼示例
- Python String index()用法及代碼示例
- Python String rindex()用法及代碼示例
注:本文由純淨天空篩選整理自 Python String ljust() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。