I tried creating a new command with an underscore as shown below, but doesn't work.
\newcommand{\h\_world}[1]{Hello World #1}
At the output I see without even initiating the command : worldHello World 1
Don't do it, unless there is a special reason to.
Underscores have special meaning (category code 8), to denote a subscript in math mode. Only catcode 11 (alphabetic) characters can be invoked in a macro name as \macroname.
Other approaches could be used to place an underscore in a macro name as shown below, but gyrations are required to invoke the macro name.
\documentclass{article}
\begin{document}
\expandafter\newcommand\csname h_world\endcsname[1]{Hello World #1}
\csname h_world\endcsname{!!!}
\end{document}
Note the space before the exclamation points is there because !!! is the argument to \csname h_world\endcsname, and shows up, after as space, as #1 in the output of that macro.
See https://en.wikibooks.org/wiki/TeX/catcode for more explanation of available catcodes.
ADDENDUM
If you were crazy and had to implement, without the use of \csname a syntax of \h_world, here is a possibility:
\documentclass{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\makeatletter
\newcommand\h{\@ifnextchar_{\haux}{\loneh}}
\makeatother
\def\tmpcompare{world}
\def\haux_#1 {\def\tmp{#1}\ifx\tmp\tmpcompare Hello World \else\loneh_#1 \fi}
\begin{document}
\newcommand\loneh{[\string\h{} undefined]}
\h blah
$\h_something blah$
\h_world blah
\bigskip\renewcommand\loneh{H}
\h blah
$\h_something blah$
\h_world blah
\end{document}
The first group of 3 lines tests
\h by itself, whose action is now defined in \loneh
\h_<incorrect keyword> where incorrect keyword is anything other than the string world. It produces the result \loneh_<incorrect keyword> where the underscore is taken with the traditional meaning.
\h_world, with the desired output.
In the first group of 3 lines \loneh is defined as [\string\h{} undefined] and in the second group of 3 lines, it is defined simply as H.
Using \def it may seem that you can use underscores in macros:
\def\nr_b{3}
\def\h_w#1{Hello #1 world!}
the number \nr_b is 3,
\h_w{wonderful}
will work exactly as requested by the OP, and produce
the number 3 is 3, Hello wonderful world!
(I tested it with pdftex , xetex , luatex, and also the respective LaTeX enginges ; all from TeX Live 2016).
I am no expert in TeX, but I think that, though, the above does not define a macro named \nr_b but rather a macro named \nr that can be only used when followed by \_b.
Moreover using underscores can have unpleasant side effects, as in this example
\def\int_{ARGH}
\[\int_\alpha\]
so I recommend against using underscores in macros.
\nr_somethingelse the previous \nr_b will no longer exist, because the actual macro is \nr in both cases. However if you change the category code of _ (with \catcode`\_=11) or use \csname nr_b\endcsname then _ will be valid in macro names. For example in expl3 we change the catcode of both _ and : so that they can be used in macro names (the change happens inside \ExplSyntaxOn/Off). See this question for an example: https://tex.stackexchange.com/q/513196/134574
– Phelype Oleinik
Oct 30 '19 at 11:56
\catcode= 11, but that may cause other issues, if you call on pre-defined macros or blend your code with pre-existing code that has not also been defined with your catcode revision in mind. – Steven B. Segletes Jun 19 '20 at 12:31