python


Python 3, receive a string as an argument without any return value


I'm learning Python and have been taking an online class. This class was very basic and I am know trying to continue my studies elsewhere. Stackoverflow.com has helped me a great deal. In the online course we didn't cover a lot about return statements, which I am now trying to learn. I would like to do something very basic, so I was thinking of creating a program that would receive a string as an argument without having any return value. I want the user to type a word that will be shown with characters or symbols between every letter.
Example
User types in the word Python.
The word will be shown as =P=y=t=h=o=n= or -P-y-t-h-o-n- or maybe with * between every letter.
Is this an easy task? Can someone help me how to go about doing this?
Thank you.
Joel
If you want to do it yourself, you can go through your string like this:
my_string = "Python"
for letter in my_string:
# do something with the letter
print(letter)
This will print each letter in your word. What you want to do is having a new string with your desired character. You probably know you can concatenate (append) two strings in this way :
str1 = "hello"
str2 = "world"
str3 = str1 + str2
print(str3) #helloworld
So to do what you'd like to do, you can see each letter as a substring of your main string, and your desired character (for example *) as another string, and build a result string in that way.
inputString = "Python"
result = ""
myChar = "*"
for letter in inputString:
# build your result
build = build + letter
print(build)
This will just copy inputString into result, though I think you'll have understood how to use it in order to add your custom chars between the letters.
Yes python makes this sort of string manipulation very easy (some other languages... not so much). Look up the standard join function in the python docs.
def fancy_print(s, join_char='-'):
# split string into a list of characters
letters = list(s)
# create joined string
output = join_char + join_char.join(letters) + join_char
# show it
print(output)
then
>>> fancy_print("PYTHON")
-P-Y-T-H-O-N-
>>> fancy_print("PYTHON", "*")
*P*Y*T*H*O*N*

Related Links

Is there a way to find a character's Unicode code point in Python 2.7?
figtext datetime function matplotlib
environment variable in ubuntu
Cross-platform Python Executables
Extract subarray from collection of 2D coordinates?
tkinter populate treeview using threading pool
How to make a function determining the winner of Tic-Tac-Toe more concise
Django update model entry using form fails
ctypes using HRESULT(python)
How to export property values with django-import-export
Plotting Coordinate Lines Using Matplotlib
BASH - Summarising information present in 2 genotype data columns in one column (ped file) [closed]
Python 3: How to call function from another file and pass arguments to that function ?
Streaming mp3 files in Django through Nginx
Opening PE file with Bokken
Python exercise: last letter / first letter

Categories

HOME
spring
crystal-reports
google-cloud-bigtable
erlang
meshlab
filterrific
voip
paramiko
facebook-graph-api
translation
jasmine
cocos2d-x-3.0
command
orientation
algorithmic-trading
data-science-experience
goutte
deeplearning4j
slim-3
packer
uiscrollview
informatica-powercenter
uiview
factor-analysis
derived
flexlm
ng2-dragula
flexboxgrid
deb
sensu
apply
tarantool
novnc
katharsis
thinking-sphinx
getjson
lego
wfp
agent
jquery-multidatespicker
ssh.net
google-account
html-agility-pack
dojox.mobile
powermta
startapp
aqgridview
data-integration
dimple.js
fontconfig
httplib2
rxvt
vici
efxclipse
system.web.ui.webcontrols
children
gitweb
gradle-eclipse
mpeg-4
flexjson
yoothemes
asymptote
android-viewholder
kendo-menu
visual-studio-code
adodb
low-level
node-imagemagick
facebook-wall
json-patch
visual-c++-2010-express
document-database
windows-mobile-6
android-contextmenu
cbcentralmanager
maven-ear-plugin
z-machine
nsindexpath
junit3
dashcode
scala-2.8
callgrind
nt4
virtualquery
usergroups

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App